Android Studio加载旧的安卓工程项目报错处理
文章目录
- Invalid Gradle JDK configuration found
- NDK not configured
- CMake '3.10.2' was not found
- 安装cmake
- 适配cmake版本号
- com.intellij.openapi.externalSystem.model.ExternalSystemException
- gradle版本过低或下载不了
- 下载gradle与依赖库超时
- 替换gradle国内源
- 替换Maven 仓库的镜像为国内源
新版本的Android Studio加载旧的安卓工程项目,会报各种问题
- Invalid Gradle JDK configuration found
- NDK not configured. Download it with SDK manager. Preferred NDK version is
- CMake ‘3.10.2’ was not found in PATH or by cmake.dir property
- com.intellij.openapi.externalSystem.model.ExternalSystemException
- gradle下载不了或time out
Invalid Gradle JDK configuration found
点击Select the Gradle JDK location
或者点击Android Studio–>Settings找到下面选项
Build, Execution, Deployment | Build Tools | Gradle
在Gradle JDK这行,选择系统中已经有的适合的。
NDK not configured
NDK not configured. Download it with SDK manager. Preferred NDK version is ‘21.1.6352462’
这里会提示未配置NDK, 且提示中会建议要配置哪个版本号,比如上图中提示的ndkVersion ‘21.1.6352462’
那么把这个建议的版本号替换到app/build.gradle中旧的版本号就行了。
修正:
app/build.gradle
diff --git a/app/build.gradle b/app/build.gradle
index 7daf6a1..a29085d 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -43,7 +43,7 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
- ndkVersion '21.3.6528147'
+ ndkVersion '21.1.6352462'
}
CMake ‘3.10.2’ was not found
错误
CMake ‘3.10.2’ was not found in PATH or by cmake.dir property.
- 可能是系统中没有安装CMake
- 也可能是系统中的Cmake版本号不对应,不是配置要求的3.10.2
安装cmake
Android Studio–> Tools-- >SDK Manager
点击选中CMake,就可以自动安装到 Android SDK的路径下
适配cmake版本号
安装成功后查看下版本号:
cmake --version指令查看,
如果安装后提示not found: cmake,则要配置下环境变量PATH
Mac中修改~/.bash_profile
把刚刚安装的cmake的bin路径加到PATH中
export PATH=$PATH:/Users/temp/Library/Android/sdk/cmake/3.30.5/bin
再次查看,就可以在命令行看到cmake指令及版本了
app/build.gradle中cmake的版本号与系统中安装的cmake版本如果不一样,也会报错,需要修改
diff --git a/app/build.gradle b/app/build.gradle
index 7daf6a1..a714679 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -36,14 +36,14 @@ android {
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
- version "3.10.2"
+ version "3.30.5"
}
}
com.intellij.openapi.externalSystem.model.ExternalSystemException
com.intellij.openapi.externalSystem.model.ExternalSystemException:
at com.intellij.gradle.toolingExtension.impl.modelAction.GradleModelFetchAction.addModels(GradleModelFetchAction.java:183)
at com.intellij.gradle.toolingExtension.impl.modelAction.GradleModelFetchAction.lambda$execute$1(GradleModelFetchAction.java:73)
at com.intellij.gradle.toolingExtension.impl.telemetry.GradleOpenTelemetry.lambda$runWithSpan$1(GradleOpenTelemetry.java:87)
at com.intellij.gradle.toolingExtension.impl.telemetry.GradleOpenTelemetry.callWithSpan(GradleOpenTelemetry.java:73)
at com.intellij.gradle.toolingExtension.impl.telemetry.GradleOpenTelemetry.callWithSpan(GradleOpenTelemetry.java:61)
at com.intellij.gradle.toolingExtension.impl.telemetry.GradleOpenTelemetry.runWithSpan(GradleOpenTelemetry.java:86)
at com.intellij.gradle.toolingExtension.impl.modelAction.GradleModelFetchAction.execute(GradleModelFetchAction.java:73)
at org.jetbrains.plugins.gradle.model.ProjectImportAction.doExecute(ProjectImportAction.java:170)
build.gradle中配置的gradle版本号过低,在高版本Android Studio中会报错
修复:
修改build.gradle中版本号为新版本
diff --git a/build.gradle b/build.gradle
index 15087da..a5a4b7d 100644
--- a/build.gradle
+++ b/build.gradle
dependencies {
- classpath "com.android.tools.build:gradle:4.1.0"
+ classpath "com.android.tools.build:gradle:7.1.1"
gradle版本过低或下载不了
gradle版本过低或下载超时提示url不存在的,可以通过修改gradle-wrapper.properties中的url来解决,把版本号改成较新的,另外把url中域名改成国内的域名,比如阿里的。
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index bc2dd44..292d061 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Wed Nov 04 15:11:01 CST 2020
+#Wed Nov 06 11:06:30 CST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
+distributionUrl=https\://mirrors.aliyun.com/macports/distfiles/gradle//gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
下载gradle与依赖库超时
Failed to resolve: com.blankj:utilcode:1.29.0
替换gradle国内源
修改grale/gradle-wrapper.properties
把distributionUrl=https://services.gradle.org/distributions/gradle-7.2-bin.zip
修改为
distributionUrl=https://mirrors.aliyun.com/macports/distfiles/gradle//gradle-7.2-bin.zip
替换Maven 仓库的镜像为国内源
修改build.gradle
buildscript {
repositories {
google()
jcenter()
}
}
allprojects {
repositories {
google()
jcenter()
}
}
改为以下内容:
buildscript {
repositories {
maven { url = uri("https://maven.aliyun.com/repository/releases") }
maven { url = uri("https://maven.aliyun.com/repository/google") }
maven { url = uri("https://maven.aliyun.com/repository/central") }
maven { url = uri("https://maven.aliyun.com/repository/gradle-plugin") }
maven { url = uri("https://maven.aliyun.com/repository/public") }
}
}
allprojects {
repositories {
maven { url = uri("https://maven.aliyun.com/repository/releases") }
maven { url = uri("https://maven.aliyun.com/repository/google") }
maven { url = uri("https://maven.aliyun.com/repository/central") }
maven { url = uri("https://maven.aliyun.com/repository/gradle-plugin") }
maven { url = uri("https://maven.aliyun.com/repository/public") }
}
}
作者:帅得不敢出门