xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] Fatal crash Android.Content.Res.Resources+NotFoundException AAPT #10901

Open devthepenguin opened 4 years ago

devthepenguin commented 4 years ago
Related #10367 ### Description On implementing splash screen in Xamarin.Android by setting the theme for activity and loading it as a drawable background in the form of LayerList throws NotFoundExcption on the drawable resource. ### Steps to Reproduce 1. Ensure that the correct drawable is associated with the "android:windowBackground" attribute. 2. Check ResourceDesigner.cs to ensure there is no mismatch in resource ids. 3. Try invoking SetContentView instead of Theme attribute and load Splash Screen by inflating a layout file (.axml) 4. Try renaming resource, clean sln, rebuild. Error persists. ### Expected Behavior Splash Screen Activity is launched ### Actual Behavior Black Screen and frequent crashes. ### Basic Information - Version with issue: - Last known good version: - IDE: Microsoft Visual Studio Community 2019 (2) Version 16.6.0 - Platform Target Frameworks:

Screenshots

splsherr resdescs

Reproduction Link

SplashScreen (2).zip

Workaround

No Workaround found.

maxim-saplin commented 4 years ago

I'm getting same crash on API Level 19 and AAB, apk works fine. I suspect recent updates to VS\Xamairn.Android broke this.

I already have the workarounds from the past in my .csproj:

<AndroidR8ExtraArguments>--no-tree-shaking</AndroidR8ExtraArguments>
<AndroidAapt2LinkExtraArgs>--no-version-vectors</AndroidAapt2LinkExtraArgs>

Here's the log:

java.lang.RuntimeException: Unable to start activity ComponentInfo{xcom.saplin.xOPS/crc64b967cc1a76f83cb7.MainActivity}: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f07005b
     FATAL EXCEPTION: main
Process: xcom.saplin.xOPS, PID: 5830
java.lang.RuntimeException: Unable to start activity ComponentInfo{xcom.saplin.xOPS/crc64b967cc1a76f83cb7.MainActivity}: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f07005b
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
    at android.app.ActivityThread.access$800(ActivityThread.java:135)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5001)
    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:785)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    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 #0x7f07005b
    at android.content.res.Resources.loadDrawable(Resources.java:2096)
    at android.content.res.Resources.getDrawable(Resources.java:700)
    at androidx.core.content.ContextCompat.getDrawable()
    at androidx.appcompat.widget.ResourceManagerInternal.getDrawable()
    at androidx.appcompat.widget.ResourceManagerInternal.getDrawable()
    at androidx.appcompat.widget.ResourceManagerInternal.checkVectorDrawableSetup()
    at androidx.appcompat.widget.ResourceManagerInternal.getDrawable()
    at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable()
    at androidx.appcompat.widget.TintTypedArray.getDrawableIfKnown()
    at androidx.appcompat.app.AppCompatDelegateImpl.attachToWindow()
    at androidx.appcompat.app.AppCompatDelegateImpl.ensureWindow()
    at androidx.appcompat.app.AppCompatDelegateImpl.onCreate()
    at androidx.appcompat.app.AppCompatActivity.onCreate()
    at crc64b967cc1a76f83cb7.MainActivity.n_onCreate(Native Method)
    at crc64b967cc1a76f83cb7.MainActivity.onCreate()
    at android.app.Activity.performCreate(Activity.java:5231)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
    ... 11 more
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
    at android.content.res.Resources.loadDrawable(Resources.java:2092)
    ... 28 more
maxim-saplin commented 4 years ago

Switching to preview update channel solved my issue (now on VS for Mac 8.7 and XF 4.6.0.800)

devthepenguin commented 4 years ago

[Update] [Workaround] downgrading to Xamarin.Forms 4.6.0.726 and disabling experimental AndroidX migration combined resolves the issue. The AAPT NotFoundException is not thrown for Xamarin.Android.Support.v7.AppCompat and Xamarin.Android.Support.v4 packages, but persists for the AndroidX migrated versions.

jsuarezruiz commented 4 years ago

Seems to be related with #10367.

devthepenguin commented 4 years ago

Seems to be related with #10367.

Yes exactly, mentioned at the top as well, only difference was there weren't any conflicts with the progaurd or r8 configs in this case.