19

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

Community
  • 1
  • 1
Red Cricket
  • 9,762
  • 21
  • 81
  • 166

2 Answers2

43

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

Red Cricket
  • 9,762
  • 21
  • 81
  • 166
2

I faced this same problem when trying to import the libgdx-cookbook samples from "Libgdx Cross-platform Game Development Cookbook" into Android Studio 2.1.1. In my case, it was solved by simply:

  • importing the /samples project;
  • not upgrading the Gradle plugin when prompted;
  • updating build.gradle file under the android subproject to make it use the buildToolsVersion and compileSkdVersion that I had:

    buildToolsVersion "23.0.3"
    compileSdkVersion 23
    
  • trying again.

So it maybe has to do with the version of the Gradle plugin.

Juan M. Molina
  • 86
  • 1
  • 2
  • 4