作为一个业余安卓开发爱好者,我并没有特别多的安卓错误排查解决经验。我自己开发的一个app,上周还用的好好的,突然就打不开了,然后我连到 android studio 上面,看了下报错日志:

我上网搜了这些报错日志的意思,也问了 chatGPT ,大概有这几种说法:
1. Clean and Rebuild the Project
Sometimes, this issue can be caused by stale build artifacts. Clean your project and rebuild it:
Clean the project: Build > Clean Project
Rebuild the project: Build > Rebuild Project
2. Invalidate Caches and Restart
Sometimes, the issue is related to corrupted cache files. You can invalidate the cache and restart Android Studio:
Go to File > Invalidate Caches / Restart…
Click on Invalidate and Restart
3. Check the Version of superfamily Library
Check if the version of the superfamily library you are using is compatible with the other dependencies in your project.【这个可能是问题之一,superfamily 的版本可能跟项目有冲突】
Make sure that you are using the correct version of the superfamily library. Sometimes, newer versions of a library introduce breaking changes or incompatibilities with other libraries.
If you are specifying the version 2.2.0 of superfamily, check if that version has any known issues or conflicts. You may want to try downgrading to an earlier version of the library or upgrading to a more recent stable version if available.
Example in build.gradle:
dependencies {
implementation ‘com.github.jakewharton:superfamily:2.2.0’ // Check version compatibility
}
4. Ensure Compatibility of Gradle and Android Plugin Versions
Sometimes, this issue can be caused by the Gradle version or the Android plugin version being incompatible with some dependencies. Ensure that both your Gradle version and Android Gradle Plugin version are up to date.
Check the gradle-wrapper.properties file to ensure you’re using a compatible version of Gradle:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
Update the Android Gradle plugin in the build.gradle file (Project level):
classpath ‘com.android.tools.build:gradle:4.2.2’
5. Force Dependency Resolution
If there are dependency conflicts, you can force Gradle to use a particular version of the library. This can be done by explicitly specifying the version to resolve conflicts.
For example:
dependencies {
implementation ‘com.github.jakewharton:superfamily:2.2.0’
implementation ‘com.squareup.okhttp3:okhttp:4.9.0’ // Example dependency
}
configurations.all {
resolutionStrategy {
force ‘com.github.jakewharton:superfamily:2.2.0’
}
}
6. Check for Dependency Conflicts
Use ./gradlew dependencies or ./gradlew app:dependencies to list all dependencies and check if there are any version conflicts between dependencies.
Open the terminal in your project root and run:
./gradlew app:dependencies
This will give you a tree view of the dependencies, and you can check if there are any version conflicts.
7. Update or Downgrade Dependencies
If you have other dependencies that may conflict with superfamily, you may need to update or downgrade them to ensure compatibility.
8. Manually Remove Unwanted AARs or Caches
If you suspect a corrupted AAR file, you can manually delete it from your project’s .gradle or .m2 cache and force Gradle to download a fresh version.
Navigate to the .gradle folder located in your project root (or ~/.gradle for global cache), and delete any folders related to superfamily.
You can also delete the Gradle cache entirely from ~/.gradle/caches.
9. Enable Debug Logging for Gradle
To get more detailed information on what Gradle is doing and where the error is happening, you can enable debug logging:
Run Gradle with the –debug flag:
./gradlew build –debug
This will provide more detailed output, which might help you pinpoint the cause of the error.
10. Check for Known Issues in the Dependency
Look for known issues with the superfamily library or any other dependencies you’re using in your build.gradle file. You can check GitHub issues for the repository to see if anyone else has encountered the same error and if there are any recommended fixes.
但是我按照其说明修改后,还是报同样的错误。
我想了一下,首先我的小米系统没有更新,说明跟小米系统没关系;然后我这个app上周还用的好好的,说明不是代码的原因。然后再仔细看看日志并上网搜了一下,大致可以确定,是 jcenter 库连不上了。
我的 build.gradle 配置如下:

先复习一下基础知识,关于安卓开发经常使用的仓库。
1、jcenter
jcenter是由 bintray.com维护的Maven仓库。可以在jcenter.bintray.com/看到整个仓库的内容。

2、mavenCentral
mavenCentral是由sonatype.org维护的Maven仓库。可以在repo1.maven.org/maven2/看到整个仓库

不管是jcenter还是mavenCentral,两者都是Maven仓库。jcenter与mavenCenter在不同的服务器上维护,由不同的人提供内容,两者之间毫无关系。在jcenter上有的可能mavenCentral上没有,反之亦然。Gradle支持从mavenCentral中央仓库和jcenter上获取构件。两个仓库都具有相同的使命:提供Java或者Androidlibrary服务。上传到哪个(或者都上传)取决于开发者
3、google仓库
在gradle4.1之后,添加了新的语法google(),用于引用google自有的仓库。很方便,但是不便于研究被依赖的aar源文件。

4、jitpack仓库
JitPack提供的仓库

5、本地仓库MavenLocal
把library放在本台电脑的上

上面这些仓库一般在国外,访问速度不稳定,在国内使用 jcenter、mavenCentral 及 google 三个远程仓库,GradleSync 会很慢,google 仓库甚至需要科学上网才能访问。为了加快Gradle Sync速度,可以优先使用阿里云镜像仓库作为下载源。
将:

替换为镜像仓库地址:
https://maven.aliyun.com/nexus/content/repositories/jcenter
https://maven.aliyun.com/nexus/content/groups/public
https://maven.aliyun.com/nexus/content/repositories/google

即 build.gradle 改成这样:

依然报错,原来是 gradle7 之后需要在 settings.gradle 中同步修改,修改成下面这样:

然后重新编译程序、安装 app ,成功!!!