Android Studio加载旧的安卓工程项目报错处理

文章目录

新版本的Android Studio加载旧的安卓工程项目,会报各种问题

  1. Invalid Gradle JDK configuration found
  2. NDK not configured. Download it with SDK manager. Preferred NDK version is
  3. CMake '3.10.2' was not found in PATH or by cmake.dir property
  4. com.intellij.openapi.externalSystem.model.ExternalSystemException
  5. 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

patch 复制代码
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.

  1. 可能是系统中没有安装CMake
  2. 也可能是系统中的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中

bash 复制代码
export PATH=$PATH:/Users/temp/Library/Android/sdk/cmake/3.30.5/bin

再次查看,就可以在命令行看到cmake指令及版本了

app/build.gradle中cmake的版本号与系统中安装的cmake版本如果不一样,也会报错,需要修改

patch 复制代码
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中版本号为新版本

patch 复制代码
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中域名改成国内的域名,比如阿里的。

patch 复制代码
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") }
    }
}

作者:帅得不敢出门

相关推荐
蘑菇丁1 小时前
ranger-kms安装
java·ide·eclipse
wind瑞2 小时前
IntelliJ IDEA插件开发-代码补全插件入门开发
java·ide·intellij-idea
阿乾之铭3 小时前
IDEA中创建多模块项目步骤
java·ide·intellij-idea
烬奇小云4 小时前
认识一下Unicorn
android·python·安全·系统安全
顾北川_野16 小时前
Android 进入浏览器下载应用,下载的是bin文件无法安装,应为apk文件
android
CYRUS STUDIO16 小时前
Android 下内联汇编,Android Studio 汇编开发
android·汇编·arm开发·android studio·arm
右手吉他16 小时前
Android ANR分析总结
android
PenguinLetsGo18 小时前
关于 Android15 GKI2407R40 导致梆梆加固软件崩溃
android·linux
杨武博21 小时前
音频格式转换
android·音视频
Byyyi耀1 天前
Jupyter notebook如何加载torch环境
ide·python·jupyter