16

Okay, I have created a completely new project in Android Studio 3.0. Gradle build works fine in this newly instantiated project, until I insert the following lines in my module's build.gradle

dependencies {
    ...
    compile 'com.github.gabrielemariotti.cards:cardslib-core:2.1.0'
    compile 'com.github.gabrielemariotti.cards:cardslib-cards:2.1.0'
    compile 'com.github.gabrielemariotti.cards:cardslib-recyclerview:2.1.0'
}

Here is the error I get in the Build log

/home/sparker0i/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.0.1.aar/e06e09188fb79d4d895b39247477d1c1/res/values/values.xml
Error:(246, 5) resource android:attr/foregroundInsidePadding is private

When I double click on it, I get a values.xml file (merged one), where the pointer is at

<dimen name="abc_action_bar_content_inset_material">16dp</dimen>

My minimum SDK version is 16, target SDK is 26. I am using Android Studio 3.0 Beta 2, build tools version is 26.0.1. Gradle plugin 3.0.0-beta2.

I bet this is because of a slightly outdated Cardslib library. Is there no way to fix this? (Removing those lines from dependencies works fine)

Sparker0i
  • 1,787
  • 4
  • 35
  • 60

4 Answers4

43

Try disabling the AAPT2 by adding android.enableAapt2=false to your gradle.properties file.

Builds may fail while AAPT2 is enabled. Additionally, AAPT2 is currently not compatible with Robelectric. If your build fails due to an AAPT2 resource processing issue or you want to use Roboelectric, you can disable AAPT2 by setting android.enableAapt2=false in your gradle.properties file and restarting the Gradle daemon by running ./gradlew --stop from the command line.

Reference : here

I was using Android studio 3.0 beta 5 In which I disabled the AAPT2 and it resolved my error.

UPDATE: 28 March 2018

With Android Studio 3.1.1 this might not work. One of your library might be using android's private resource. You need to find the error causing library and replace android:attr/foregroundInsidePadding with foregroundInsidePadding and import it to your project.

  1. Clone the library repo in your local.
  2. Open repository in Android Studio find xml having <attr name="android:foregroundInsidePadding" /> and replace it with
    <attr name="foregroundInsidePadding" /> and Build.
  3. Open your project and import that repository as dependency into your project.
  4. Remove library compile statements from app level build.gradle.
  5. Now you might be able to use AAPT2 so try changing android.enableAapt2=false to true in gradle.properties if present.
Nilesh Deokar
  • 2,975
  • 30
  • 53
3

This is because you shouldn't use the 'android' namespace for this resource. To resolve this issue, replace android:foregroundInsidePadding with foregroundInsidePadding.
More info on the Android Studio AAPT2 migration guide.

Izabela Orlowska
  • 7,431
  • 2
  • 20
  • 33
  • I neither used android:foregroundInsidePadding nor foregroundInsidePadding anywhere inside my code. It all happened because of including that particular library. Without that the code runs great. It's also okay if we disable aapt2 – Sparker0i Oct 31 '17 at 15:48
  • 1
    Ah, in that case the owner of the library needs to update their code to remove the "android" namespace for foregroundInsidePadding. Or you can fork their library, modify the resource and then build as a local library module. – Izabela Orlowska Nov 01 '17 at 11:45
0

I updated my dependencies from :

compile 'com.android.support:support-v4:19.1.0'
compile 'com.android.support:appcompat-v7:19.1.0'

to

compile 'com.android.support:support-v4:21.0.1'
compile 'com.android.support:appcompat-v7:21.0.1'

And it worked for me

Gabrielkdc
  • 105
  • 1
  • 11
  • That will work only if you are targeting a lower release of Android. In my case I'm targeting a higher release. – Sparker0i Feb 27 '18 at 03:51
  • Why the downvote? Someone already answered to you. It worked for me and maybe would help someone as well. Sometimes we have similar issues but the accepted answer doesn't work for everybody, and sometimes we find an answer that help in our specific case by reading non accepted answers. That's why I shared my answer. – Gabrielkdc Mar 06 '18 at 07:05
  • It might give runtime errors if you are targeting a very recent release of Android like API 27 – Sparker0i Mar 08 '18 at 08:40
0

Try this: Disable AAPT2 by adding android.enableAapt2=false in gradle-properties. Also ensure you have the compileSdkVersion and targetSdkVersion are the same version. Mine is 28 with android studio 3.2.1.

Rebuild your project it should work.

Mwongera808
  • 880
  • 11
  • 16