Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot set the value of read-only property 'jniFolders' on task ':android:packageDebug'

I wanted to open up and project in Android studio that I haven't worked on in a while, but when Android Studio tries to load the project it fails with this error message:

Error:(21, 0) Cannot set the value of read-only property 'jniFolders' on task ':android:packageDebug'.

I click on the link to the build.gradle and I guess these lines are the problem ...

// needed to add JNI shared libraries to APK when compiling on CLI
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
    pkgTask.jniFolders = new HashSet<File>()
    pkgTask.jniFolders.add(new File(projectDir, 'libs'))
}

I see an answer here: Google AppInvites break build that says to ...

Fixed by adding this instead:

android {
  sourcesets {
    main {
      jniLibs.srcDir new File(buildDir, 'lib')
    {
  }
}

But the above answer is not very clear. I am not sure what line to change and the braces in the answer do not seem to match up.

I am at a total loss at what to do? Any help is appreciated.

Thanks

like image 313
Red Cricket Avatar asked Mar 06 '16 04:03

Red Cricket


1 Answers

Ok I had to change the start of my build.gradle file to this ....

android {
    buildToolsVersion project.androidToolsVersion
    compileSdkVersion project.androidSDKVersion.toInteger()
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDir 'libs'
        }

        instrumentTest.setRoot('tests')
    }
}

/*RBC
// needed to add JNI shared libraries to APK when compiling on CLI
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
    pkgTask.jniFolders = new HashSet<File>()
    pkgTask.jniFolders.add(new File(projectDir, 'libs'))
}
RBC*/

I added the line:

jniLibs.srcDir 'libs'

and I commented out

// needed to add JNI shared libraries to APK when compiling on CLI
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
    pkgTask.jniFolders = new HashSet<File>()
    pkgTask.jniFolders.add(new File(projectDir, 'libs'))
}

In the C:\Users\plankton\Desktop\ThePlaneThatCouldntFly\flappytrip\android\build.gradle file.

I came about this solution after reading this https://github.com/libgdx/libgdx/issues/3027

like image 96
Red Cricket Avatar answered Oct 05 '22 15:10

Red Cricket