4

When I add the core-ktx dependency to my app's build.gradle file, my gradle builds fail with the error message AAPT2 error: check logs for details It furthermore tells that there are two attributes missing in values.xml. This file is located under the .gradle folder inside my user directory.
when I add android.enableAAPT2=false to my project properties, the build fails due to that option being deprecated so I want to avoid that.
The error descriptions of the two resource not found errors are the following:

error: resource android:attr/fontVariationSettings not found. Message{kind=ERROR, text=error: resource android:attr/fontVariationSettings not found., sources=[C:\Users\Marc.gradle\caches\transforms-1\files-1.1\appcompat-v7-26.1.0.aar\b6d4f8d4d33639ae469eaec181e24176\res\values\values.xml], original message=, tool name=Optional.of(AAPT)}

When I add different ktx libraries everything is just fine. It builds properly and I can even import androidx.collections! How can I add the core-ktx library without any errors?

project

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
Zonico
  • 192
  • 1
  • 11

1 Answers1

9

You are using 'AndroidX' which is only available if you set your compileSdkVersion 'android-P' and targetSdkVersion 28. Then in AndroidStudio go to Refactor -> Refactor to AndroidX and everything should work fine now :).

Rene Ferrari
  • 4,096
  • 3
  • 22
  • 28
  • 1
    Thank you! I've downloaded Android Studio 3.2 and it kinda works.It builds but Android Studio bugs a little. Anyway thank you very much for your anwer, really appreciate your effort :)' Edit: Omg it works, FINALLY. Thank you dude, people like you are the real heroes! – Zonico May 23 '18 at 14:14
  • 1
    Another thing is that I think one of the appcompat libraries got released with references to some platform attributes that were only added in API 28 (android P) and when you use them you run into the same error. In both cases @ReneFerrari's solution works. :) – Izabela Orlowska May 23 '18 at 16:04