Android Studio 1.3.2已经支持NDK的编译,调试。但是已经跟老的项目通过配置 Application.mk,Android.mk来编译NDK的形式完全不同了。参考编译配置文档,采用了Gradle 2.5的配置方式(详细配置参考 Android Studio 1.3 配置编译NDK参考文档,Google官方链接),结果在编译报错,显示如下信息:
Error:Unable to load class 'com.android.build.gradle.managed.ProductFlavor_Impl'.
Possible causes for this unexpected error include:
Possible causes for this unexpected error include:
- You are using JDK version 'java version "1.7.0_80"'. Some versions of JDK 1.7 (e.g. 1.7.0_10) may cause class loading errors in Gradle.
Please update to a newer version (e.g. 1.7.0_67).
Open JDK Settings - Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network) - The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart) - Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
查找了好长时间原因,最后发现,是由于build.gradle中修改有问题。
先看看有问题的build.gradle,注意defaultConfig.with部分的差别
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
apply plugin: 'com.android.model.application' model { android { compileSdkVersion = 23 buildToolsVersion = "23.0.0" defaultConfig.with { applicationId = "com.helloworld" minSdkVersion = 14 targetSdkVersion = 22 } } android.buildTypes { release { minifyEnabled = false proguardFiles += file('proguard-rules.txt') } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.2.0' } |
修改后的为(注意defaultConfig.with部分的差别
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
apply plugin: 'com.android.model.application' model { android { compileSdkVersion = 23 buildToolsVersion = "23.0.0" defaultConfig.with { applicationId = "com.helloworld" minSdkVersion.apiLevel = 14 targetSdkVersion.apiLevel = 22 } } android.buildTypes { release { minifyEnabled = false proguardFiles += file('proguard-rules.txt') } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.2.0' } |
一个疏忽,浪费时间很多啊!