Android Studio 打包App问题

一、场景

windows 电脑C 盘空间越来越少,所有软件默认位置都往C盘用户目录写入数据,于是开始准备整理,Android Studio 相关的 .android 和 .gradle 目录成为了目标。

二、问题出现

1、将C盘的.gradle 目录拷贝到D盘,文件比较大,拷贝了很久,其中还有一些文件无法操作跳过处理的。

2、设置Android stuido gradle 目录到D 盘对应目录

3、编译App 代码,报错如下:

Could not resolve all files for configuration ':app:NormalAppDebugRuntimeClasspath'. > Could not find com.lzy.net:okgo:3.0.4. Required by: project :app > Could not find org.eclipse.paho:mqtt-client:0.4.0. Required by: project :app

但是找到对应的gradle目录,发现之前已经拷贝过来了:

但是仍然报这个错误,有点莫名其妙,怀疑是不是拷贝过来还有其他文件丢失损坏导致找不到这个三方库依赖。

三、解决尝试

1、重新拷贝一份代码,将原先C盘的.android .gralde 重命名,然后让Android studio 重新运行生成新的目录,打包编译还是不行。首先发现的是gradle 下载速度奇慢,后来参考解决gradle下载慢的问题-阿里云开发者社区

更换了腾讯的镜像源:

下载gradle 就很快了, 然后再看.gradle 目录下,确实没有下载到okgo 这个依赖包, 然后将原先D盘中拷贝过来,也还是识别不到,仍然编译不过。

2、怀疑是不是这个库在几个源里面下载不到了

复制代码
google()
jcenter()
mavenCentral()

jcenter 里面确实没找到, mavenCentral 的网页里面 Maven Central 找到的包名对不上。

然后重新添加了阿里的镜像源

复制代码
maven {
    url 'https://maven.aliyun.com/repository/public/'
}
maven {
    url 'https://maven.aliyun.com/repository/central'
}

居然就成功获取下来了仓库服务

后面咨询了一下AI , 也建议将小的不更新的库放到本地打包,所以这些jar aar 还是放到libs 下管理,不知道什么时候又可能拉取不到了。

【但是将库文件放到本地,只适合简单的没有其他依赖拉取的小文件,这个okgo应该还有其他依赖,如果放到本地打包会报如下错误:】

02-12 13:59:38.267 16706 18109 E AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher

02-12 13:59:38.267 16706 18109 E AndroidRuntime: Process: com.org.BaseWebviewApp, PID: 16706

02-12 13:59:38.267 16706 18109 E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/internal/http/HttpHeaders;

02-12 13:59:38.267 16706 18109 E AndroidRuntime: at com.lzy.okgo.interceptor.HttpLoggingInterceptor.logForResponse(HttpLoggingInterceptor.java:166)

02-12 13:59:38.267 16706 18109 E AndroidRuntime: at com.lzy.okgo.interceptor.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:101)

02-12 13:59:38.267 16706 18109 E AndroidRuntime: at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:190)

02-12 13:59:38.267 16706 18109 E AndroidRuntime: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)

02-12 13:59:38.267 16706 18109 E AndroidRuntime: at okhttp3.RealCall.access$100(RealCall.java:30)

02-12 13:59:38.267 16706 18109 E AndroidRuntime: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)

02-12 13:59:38.267 16706 18109 E AndroidRuntime: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)

02-12 13:59:38.267 16706 18109 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)

02-12 13:59:38.267 16706 18109 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)

02-12 13:59:38.267 16706 18109 E AndroidRuntime: at java.lang.Thread.run(Thread.java:932)

02-12 13:59:38.267 16706 18109 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "okhttp3.internal.http.HttpHeaders" on path: DexPathList[[zip file "/data/app/com.org.BaseWebviewApp-x9N_Ov65Y47KeF4Y4EvTHA==/base.apk"],nativeLibraryDirectories=[/data/app/com.org.BaseWebviewApp-x9N_Ov65Y47KeF4Y4EvTHA==/lib/arm64, /data/app/com.org.BaseWebviewApp-x9N_Ov65Y47KeF4Y4EvTHA==/base.apk!/lib/arm64-v8a, /system/lib64, /hw_product/lib64, /system/product/lib64]]

一个清理磁盘空间,又整了半天,还是要弄懂本源,知道各个目录的作用, .android 目录中其实主要还是avd 占用空间, sdk 目录早已经移动出来了。

相关推荐
睡觉待开机1 小时前
【Android】03-Android 开发机器配置要求
android
陈逸轩*^_^*1 小时前
idea打不开,idea打不开,Error occurred during initialization of VM
java·ide·intellij-idea
Rverdoser2 小时前
非线性优化--NLopt算法(Android版本和Python示例)
android·python·算法
大胃粥3 小时前
Android V app 冷启动(6) Transition 数据化
android
帅次3 小时前
Flutter:StatelessWidget vs StatefulWidget 深度解析
android·flutter·ios·小程序·swift·webview·android-studio
好看资源平台4 小时前
安卓逆向环境搭建(Windows/Linux双平台)
android·linux·windows
大三开学菜鸟4 小时前
记录一下子模块不被idea加载情况
java·ide·intellij-idea
林奋斗同学4 小时前
Android GMS集成
android
_一条咸鱼_5 小时前
Android Glide 框架线程管理模块原理的源码级别深入分析
android
_一条咸鱼_5 小时前
Android Retrofit 框架注解定义与解析模块深度剖析(一)
android