- Home /
Unity Android build support for support v7 v24.x.x
I have been trying to update my plugin to use support libs v24.x.x I use appcompat support v7 library in my plugin and facing a runtime crash whenever I start an activity that extends AppCompatActivity :
Following is the crash trace : 09-28 15:23:55.721 16455-16455/com.example.qotdapp E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.qotdapp, PID: 16455 java.lang.RuntimeException: Unable to start activity ComponentInfo {com.example.qotdapp/com.example.qotdapp.MainActivity} : android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f02004f at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471) at android.app.ActivityThread.access$900(ActivityThread.java:175) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5602) 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:1283) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) at dalvik.system.NativeStart.main(Native Method) Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f02004f at android.content.res.Resources.loadDrawable(Resources.java:3422) at android.content.res.Resources.getDrawable(Resources.java:1909) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:346) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:194) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:182) at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:717) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:187) at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:77) at android.support.v7.app.AppCompatDelegateImplBase.(AppCompatDelegateImplBase.java:127) at android.support.v7.app.AppCompatDelegateImplV9.(AppCompatDelegateImplV9.java:147) at android.support.v7.app.AppCompatDelegateImplV11.(AppCompatDelegateImplV11.java:27) at android.support.v7.app.AppCompatDelegateImplV14.(AppCompatDelegateImplV14.java:50) at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:201) at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:181) at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:521) at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71) at com.example.qotdapp.MainActivity.onCreate(MainActivity.java:102) at android.app.Activity.performCreate(Activity.java:5451) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471) at android.app.ActivityThread.access$900(ActivityThread.java:175) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5602) 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:1283) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) at dalvik.system.NativeStart.main(Native Method) Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:986) at android.graphics.drawable.Drawable.createFromXml(Drawable.java:930) at android.content.res.Resources.loadDrawable(Resources.java:3418) at android.content.res.Resources.getDrawable(Resources.java:1909) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:346) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:194) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:182) at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:717) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:187) at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:77) at android.support.v7.app.AppCompatDelegateImplBase.(AppCompatDelegateImplBase.java:127) at android.support.v7.app.AppCompatDelegateImplV9.(AppCompatDelegateImplV9.java:147) at android.support.v7.app.AppCompatDelegateImplV11.(AppCompatDelegateImplV11.java:27) at android.support.v7.app.AppCompatDelegateImplV14.(AppCompatDelegateImplV14.java:50) at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:201) at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:181) at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:521) at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71) at com.example.qotdapp.MainActivity.onCreate(MainActivity.java:102) at android.app.Activity.performCreate(Activity.java:5451) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471) at android.app.ActivityThread.access$900(ActivityThread.java:175) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5602) 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:1283) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) at dalvik.system.NativeStart.main(Native Method)
Android suggested a fix via gradlle upgrade to 2.2 or adding a flag in the gradle script here : http://stackoverflow.com/questions/35739743/file-res-drawable-abc-ic-ab-back-material-xml-from-drawable-resource-id-0x7f020/35740506#35740506
The new gradle update by default adds the "--no-version-vector" flag when running the aapt command and that resolves the issue. But Unity android build command does not add this flag, hence using appcompat lib 24.x.x always crashes. The issue does not occur when using appcompat 23.4.0.
Is there a way to add this flag to the aapt command executed by Unity build process? Or any other way i can fix this crash?
Answer by liortal · Oct 05, 2016 at 06:11 AM
Is there a way to add this flag to the aapt command executed by Unity build process? Or any other way i can fix this crash?
No, Unity is "hard wired" to use a specific set of arguments to the build tools.
In latest 5.5 beta, you can build your Unity project into a Gradle project that can be further customized and only then built using Gradle. Not sure whether this is a viable option for you.
The issue that is causing the crash is this:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.qotdapp, PID: 16455 java.lang.RuntimeException: Unable to start activity ComponentInfo {com.example.qotdapp/com.example.qotdapp.MainActivity} : android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f02004f
You are missing some drawable resource (abc_vector_test). Check if your libraries + build tools all have compatible versions (e.g: build tools 24.x with support lib 24.x, etc)
EDIT: According to this link this is an "expected" issue, which should be solved either by adding an extra parameter to the gradle build file, or an argument to AAPT.
The article also mentions a "magic" way, you can try that by adding the following code to your activity code:
static {
AppCompatDelegate.setCompatVectorFromSourcesEnabled(true);
}
You can give that a try to see if that works for you.
Other, hacky & crazier suggestions:
Export a "Google android" project and then import that into Android studio and add whatever flags you need.
Since the AAPT parameters are "hard coded", you could create a dummy aapt file that will act as a proxy between Unity and the real aapt file. Its only job will be to add the --no-version-vectors args (on top of the args passed by Unity). This will "simulate" a scenario where Unity actually adds this argument itself.
Use the latest beta with gradle support :) and hope it just works.
Thanks for a quick response.
I do have the file as a resource in the generated apk. I decompiled the apk and checked for all the indications for the error but didnt find any. The aapt build command actually affects whether this abc_vector_test gets added as a resource or not.
I double checked the build-tools, platform-tools versions , it points to 24.x version. Is there any other way to make it work? Are there reported issues for Android Nougat support on Unity? I didnt find any yet hence the question.
Would really appreciate all the help.
I tried the code change :
static {
AppCompatDelegate.setCompatVectorFromSourcesEnabled(true);
}
Does not seem to work. I think exporting to gradle project would be the way but currently i had to switch back to 23.4.0 support libs.
Hope Unity fixes this in android builds since many developers are going to start integrating with appcompat support libs 24.x
Thanks for the help!
Your answer
Follow this Question
Related Questions
can not select android root folder 1 Answer
Android build failes because of manifest 0 Answers
Unity tries wrong Android "run device" 1 Answer
Cannot install apk in android 8.0.0 (API level 26) 0 Answers