找不到属性jni和源设置’main’
apply plugin: 'com.android.model.application' model { android { compileSdkVersion = 21 buildToolsVersion = "22.0.1" defaultConfig.with { applicationId = "com.example.native_activity" minSdkVersion.apiLevel = 9 targetSdkVersion.apiLevel = 9 } sourceSets.main { jni.srcDirs = [] // This prevents the auto generation of Android.mk jniLibs.srcDir = 'src/main/libs' // This is not necessary unless you have precompiled libraries in your project. } }
这是堆栈跟踪:
Caused by: org.gradle.model.internal.core.ModelRuleExecutionException: Exception thrown while executing model rule: model.android at org.gradle.model.internal.registry.DefaultModelRegistry.fireMutation(DefaultModelRegistry.java:485) at org.gradle.model.internal.registry.DefaultModelRegistry.access$1500(DefaultModelRegistry.java:45) at org.gradle.model.internal.registry.DefaultModelRegistry$RunModelAction.apply(DefaultModelRegistry.java:1464) at org.gradle.model.internal.registry.DefaultModelRegistry.transitionTo(DefaultModelRegistry.java:341) at org.gradle.model.internal.registry.DefaultModelRegistry.transition(DefaultModelRegistry.java:419) at org.gradle.model.internal.registry.DefaultModelRegistry.atStateOrMaybeLater(DefaultModelRegistry.java:183) at org.gradle.model.internal.registry.DefaultModelRegistry.atStateOrLater(DefaultModelRegistry.java:175) at org.gradle.execution.TaskNameResolver.selfClose(TaskNameResolver.java:101) at org.gradle.execution.TaskNameResolver.selfClosedTasksNode(TaskNameResolver.java:114) ... 60 more Caused by: org.gradle.api.internal.MissingMethodException: Could not find method main() for arguments [build_f1cmjkxjjzysskbrs6852ixyj$_run_closure1_closure2_closure7@8c09fa7] on SourceSet container.
我在最近2个小时里用疯狂的Google搜索…
解决方法
正如Awanish所说 – 非常仔细地阅读
Experimental Plugin User Guide一步一步.要获得更多许可,请检查google提供的
ndk-samples中的build.gradle文件.
sourceSets.main {}具有不同的语法,应该在android {}块之外.在你的情况下,它应该看起来像这样:
model { android { //... } android.sources { main { jniLibs { source { srcDirs 'libs' } } } } }