29

I update android-studio 3.0 from canary 5 to canary 6 and suddenly My app gives crash on KitKat(API 19) with below stacktrace.

The Main2Activity.java:10 line is the first line in my activity onCreate() method.

07-11 13:00:39.523 8913-8913/dcpl.com.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
  Process: dcpl.com.myapplication, PID: 8913
  java.lang.RuntimeException: Unable to start activity ComponentInfo{dcpl.com.myapplication/dcpl.com.myapplication.Main2Activity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f070058
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2318)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
      at android.app.ActivityThread.access$800(ActivityThread.java:139)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:149)
      at android.app.ActivityThread.main(ActivityThread.java:5257)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:515)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
      at dalvik.system.NativeStart.main(Native Method)
   Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070058
      at android.content.res.Resources.getValue(Resources.java:1173)
      at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:332)
      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190)
      at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:711)
      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:195)
      at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81)
      at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:131)
      at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:155)
      at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:31)
      at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:55)
      at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:205)
      at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
      at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
      at dcpl.com.myapplication.Main2Activity.onCreate(Main2Activity.java:10)
      at android.app.Activity.performCreate(Activity.java:5411)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396) 
      at android.app.ActivityThread.access$800(ActivityThread.java:139) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:149) 
      at android.app.ActivityThread.main(ActivityThread.java:5257) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633) 
      at dalvik.system.NativeStart.main(Native Method) 

How can I solve it?

Pang
  • 9,564
  • 146
  • 81
  • 122
nilesh
  • 519
  • 4
  • 17

4 Answers4

37

Seems like the issue is related to Aapt 2.

Put

android.enableAapt2=false

In your gradle.properties file and it fixes the issue for me.

Benoit
  • 1,168
  • 8
  • 16
  • I have another problem, I'm unable to share the generated APK. It always fails wile installing via Fabric or Diawi. Installs only with USB debugging.This happens even with simple 'Hello World' project. So My question is , can't we build and share APK from Canary channel? – DroidLearner Jul 12 '17 at 02:50
  • I don't think I have the same issue, I just tested on a project and can upload the APK to bitrise and install it on a phone. – Benoit Jul 12 '17 at 08:20
  • Oh strange. I've tested it both at work place & home. It didn't work out :( – DroidLearner Jul 12 '17 at 12:31
  • 1
    Above does not even build for me on 3.0 Canary 6. It starts giving errors like: Information:Gradle tasks [:mobile:assembleDebug] ...\src\main\res\layout\profile_activity.xml Error:(61, 39) No resource found that matches the given name (at 'labelFor' with value '@id/my_profile_first_name_edit'). – Farrukh Najmi Jul 12 '17 at 23:10
  • 1
    @DroidLearner I stuck with same issue on Diawi, I share release build instead of debut and it works fine for me. – nilesh Jul 13 '17 at 04:38
  • 2
    @Farrukh Najmi it is possible that you use resource (@id/my_profile_first_name_edit) before it get declares, try to add like this(@+id/my_profile_first_name_edit) instead. – nilesh Jul 13 '17 at 04:42
  • Yes, my bet on that too nilesh, had the same issue and fixed it this way. – Benoit Jul 13 '17 at 07:30
  • Yes It's works for me!! , One question, How you know this will work, is there any available in doc? can you please provide that link @Benoit thanks – Mahesh Kavathiya Jul 13 '17 at 09:34
  • @MaheshKavathiya check https://stackoverflow.com/questions/5025910/difference-between-id-and-id-in-android link – nilesh Jul 13 '17 at 11:36
  • 1
    @nilesh Yes changing the '@id' to '@+id' fixed my problem. Thank you! – Farrukh Najmi Jul 13 '17 at 19:25
  • This solved my problem with abc_vector_test not being found. Thank you so much +1 on AS 3.0.0 Canary 6 – Reid Mac Jul 17 '17 at 16:50
  • what if it fails to find stuff such as @color/light_blue or @dimen/d2? – X-HuMan Jul 18 '17 at 09:56
  • There is no resource in ur color resource file with name light_blue. – nilesh Jul 18 '17 at 17:10
  • @nilesh there are these resource in another library module which is included as an API – X-HuMan Jul 20 '17 at 12:10
  • @DroidLearner Can you check the manifest in the apk and see if the testOnly attribute is set to true in the application tag. If that's true, the apk can only be installed via adb. To generate an apk without the testOnly flag, use Build --> Generate Apk. – Rahul Sainani Jul 26 '17 at 09:01
5

I have the same issue.

put

android.enableAapt2=false

AAPT2. We are continuing to stabilize AAPT2 which enables incremental resource processing. If your build fails due to resource processing issue, please send us a bug report. To temporarily disable AAPT, set android.enableAapt2=false in your gradle.properties file. Roboelectric is currently not compatible with AAPT2

follow the below link

https://androidstudio.googleblog.com/2017/06/android-studio-30-canary-5-is-now.html

Android Tutorial
  • 829
  • 1
  • 8
  • 20
  • in my case adding this line caused inflanting error. I've move back to canary5. Also selector of items that are drawables not working on api19 – murt Jul 12 '17 at 16:15
4

I had the same problem. To solve it, just update to Android Studio 3.0 Canary 7.

Fixes:
63623801 ResourceNotFoundException running Kotlin project on API 16 AVD after upgrading to Canary 6

Release notes

Kevin Robatel
  • 8,025
  • 3
  • 44
  • 57
2

add this code in my project

android.enableAapt2=false

solved one of my issues: with Android Studio 3.0 : canary 6, Gen a signed APK by default which can't parsered by "AXmlResourceParser.java"(axmlprinter2-2.0.jar)

Jackie Cheng
  • 190
  • 1
  • 9