Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Could not find property jni 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 stacktrace:

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.

I googled like mad for the last 2 hours...

like image 240
John Difool Avatar asked Jul 20 '15 01:07

John Difool


People also ask

What is the latest version of Android Gradle?

Download the latest Gradle distribution The current Gradle release is version 7.5.1, released on 05 Aug 2022. The distribution zip file comes in two flavors: Binary-only.


1 Answers

As Awanish said - read the Experimental Plugin User Guide step by step VERY carefully. For even more clearance check the build.gradle files in the ndk-samples provided by google.

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

model {

    android {
        //...
    }

    android.sources {
        main {
            jniLibs {
                source {
                    srcDirs 'libs'
                }
            }
        }
    }

}
like image 183
tochkov Avatar answered Nov 12 '22 08:11

tochkov