Android Studio 1.3 gradle plugin returns an error when defining jni and jniLibs in source sets

Could not find jni property and source set '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. } } 

Here is the stack:

 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. 

For the past 2 hours, I looked insanely insane ...

+6
source share
4 answers

As Avanish said, carefully read the Experimental Plugin User Guide step by step VERY . For even more verification, check out the build.gradle files in the ndk samples provided by Google.

sourceSets.main { } has a different syntax and must be outside the android { } block. In your case, it should look something like this:

 model { android { //... } android.sources { main { jniLibs { source { srcDirs 'libs' } } } } } 
+9
source

In my case, it was the exact opposite of point:

This syntax - with jniLibs outside the android block - gave me an error:

 android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "com.mycompany.myproject" minSdkVersion 17 targetSdkVersion 21 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } sourceSets { main { jniLibs.srcDirs = ['src/main/jniLibs'] } } 

and this syntax - inside the android block - fixed it:

 android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "com.mycompany.myproject" minSdkVersion 17 targetSdkVersion 21 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } sourceSets { main { jniLibs.srcDirs = ['src/main/jniLibs'] } } } 
+3
source

It looks like you are trying to use a class test plugin!

Make sure you have class 2.5 in your gradle-wrapper.properties :

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

and this is the build.gradle tag in your build.gradle project

 classpath 'com.android.tools.build:gradle-experimental:0.1.0' 

Instead of guessing a lot of things, let me redirect you to the user guide, where the documentation describes in detail the transition from the standard to the experimental plugin. Look at here!

Try these fixes. Post more details if they don’t work for you, I will try to help. :)

+1
source
 apply plugin: 'com.android.model.application' model { android { compileSdkVersion 23 buildToolsVersion "23.0.3" defaultConfig { applicationId "com.example.jeremy.test" minSdkVersion.apiLevel = 15 targetSdkVersion.apiLevel = 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false //proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles.add(file('proguard-android.txt')) } } ndk { moduleName "hello-android-jni" } } android.sources.main { java.source.srcDirs = ["src/main/java", "/Users/jeremy/Repositories/hello/src/android/java"] } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0' } 

The above is copied from my ndk pilot project, this works for me. See section android.sources.main .

0
source

All Articles