Android Studio升级4.1后老项目ndk无法使用问题 NDK not configured问题处理方式

Android Studio升级4.1后老项目ndk无法使用问题 NDK not configured问题处理方式,第1张

Android studio升级4.1后打开以前项目,提示ndk无效,如下:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':SerialPortLibrary'.
> NDK not configured. C:\Users\lenovo\AppData\Local\Android\Sdk\ndk-bundle
  Download it with SDK manager.

打开Project Structure:配置也无法更改ndk路径:

原因在于Android studio4.1版本已不需要指定ndk位置,只需要指定ndk版本即可。

解决方案:

1、打开Project Structure->Modules->NDK Version为项目每一个Module指定NDK版本

2、同步项目

3、同步完成后,会在各Module下build.gradle文件android下添加一行:ndkVersion '22.1.7171670'

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion '26.0.2'

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        externalNativeBuild {
            cmake {
                arguments '-DANDROID_TOOLCHAIN=clang'
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
        }
    }
    ndkVersion '22.1.7171670'
}

4、若添加后同步项目,出现如下错误,表示当前项目使用的gradle版本过低,无法使用这种方式配置,需升级。


A problem occurred evaluating project ':SerialPortLibrary'.
> Could not find method ndkVersion() for arguments [22.1.7171670] on object of type com.android.build.gradle.LibraryExtension.

5、修改项目跟目录下build.gradle文件classpath版本号如: 

classpath "com.android.tools.build:gradle:3.0.1"

然后修改项目gradle->wrapper->gradle-wrapper.properties文件gradle版本号为4.1

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
#Wed Dec 13 14:32:36 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/992360.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存