Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample Android Redex APK Crashing: android.view.InflateException: Error inflating class com.google.android.material.textfield.TextInputLayout #822

Closed
shubhamguptadream11 opened this issue Aug 18, 2023 · 3 comments

Comments

@shubhamguptadream11
Copy link

shubhamguptadream11 commented Aug 18, 2023

When I am trying to pass sample release android apk to redex. The build was crashing with below logs.
Proguard is disabled.

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #27 in com.example.myapplication:layout/activity_main: Binary XML file line #27 in com.example.myapplication:layout/activity_main: Error inflating class com.google.android.material.textfield.TextInputLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3616)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3780)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2251)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:233)
at android.app.ActivityThread.main(ActivityThread.java:8035)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
Caused by: android.view.InflateException: Binary XML file line #27 in com.example.myapplication:layout/activity_main: Binary XML file line #27 in com.example.myapplication:layout/activity_main: Error inflating class com.google.android.material.textfield.TextInputLayout
 Caused by: android.view.InflateException: Binary XML file line #27 in com.example.myapplication:layout/activity_main: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: java.lang.reflect.InvocationTargetException 
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:852)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1131)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1092)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:775)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:197)
at com.example.myapplication.MainActivity.onCreate(MainActivity.kt:10)
at android.app.Activity.performCreate(Activity.java:8006)
at android.app.Activity.performCreate(Activity.java:7990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3589)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3780)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2251)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:233)
at android.app.ActivityThread.main(ActivityThread.java:8035)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
2023-08-18 16:33:44.978  9955-9955  AndroidRuntime          usap64                               E  Caused by: android.view.InflateException: Binary XML file line #20 in com.example.myapplication:layout/design_text_input_start_icon: Binary XML file line #20 in com.example.myapplication:layout/design_text_input_start_icon: Error inflating class pathInterpolator
Caused by: android.view.InflateException: Binary XML file line #20 in com.example.myapplication:layout/design_text_input_start_icon: Error inflating class pathInterpolator
Caused by: java.lang.ClassNotFoundException: android.view.pathInterpolator
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at android.view.LayoutInflater.createView(LayoutInflater.java:813)
at android.view.LayoutInflater.createView(LayoutInflater.java:774)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:911)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:928)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:948)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1002)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.inflate(LayoutInflater.java:657)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at com.google.android.material.textfield.StartCompoundLayout.<init>(StartCompoundLayout.java:95)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:484)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:451)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:852)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1131)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1092)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:775)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:197)
at com.example.myapplication.MainActivity.onCreate(MainActivity.kt:10)
at android.app.Activity.performCreate(Activity.java:8006)
at android.app.Activity.performCreate(Activity.java:7990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3589)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3780)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2251)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:233)
at android.app.ActivityThread.main(ActivityThread.java:8035)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
 Caused by: java.lang.ClassNotFoundException: android.view.pathInterpolator

redex command: python3 redex.py $1 -o $2 -P proguard-rules.pro -c config/default.config --sign -s ./debug.keystore -a AndroidDebugKey -p android

default.config

  "redex" : {
    "passes" : [
      "ReBindRefsPass"
    ]
  }
}

proguard-rules.pro

-keep class com.** { *; }

# keep everything in this package from being renamed only
-keepnames class com.** { *; }

# keep everything in this package from being removed or renamed
-keep class android.** { *; }

# keep everything in this package from being renamed only
-keepnames class android.** { *; }

# keep everything in this package from being removed or renamed
-keep class com.google.android.material.** { *; }

# keep everything in this package from being renamed only
-keepnames class com.google.android.material.** { *; }

# keep everything in this package from being removed or renamed
-keep class android.view.** { *; }

# keep everything in this package from being renamed only
-keepnames class android.view.** { *; }

# keep everything in this package from being removed or renamed
-keep class com.google.android.material.textfield.** { *; }

# keep everything in this package from being renamed only
-keepnames class com.google.android.material.textfield.** { *; }

# keep the class and specified members from being removed or renamed
-keep class com.google.android.material.textfield.TextInputLayout { *; }

# keep the specified class members from being removed or renamed 
# only if the class is preserved
-keepclassmembers class com.google.android.material.textfield.TextInputLayout { *; }

# keep the class and specified members from being renamed only
-keepnames class com.google.android.material.textfield.TextInputLayout { *; }

# keep the specified class members from being renamed only
-keepclassmembernames class com.google.android.material.textfield.TextInputLayout { *; }

# keep everything in this package from being removed or renamed
-keep class androidx.** { *; }

# keep everything in this package from being renamed only
-keepnames class androidx.** { *; }

# keep everything in this package from being removed or renamed
-keep class com.google.android.material.internal.** { *; }

# keep everything in this package from being renamed only
-keepnames class com.google.android.material.internal.** { *; }

Sample APK with redex and Sample APK without redex are provided in below zip
sample-apks.zip

This crash is specifically happening when I am trying to add com.google.android.material.textfield.TextInputLayout in my xml file in release build only.
Everything is working fine in debug builds

I tried different redex configs and tried keeping this class in proguard.pro as well. But didn't worked.

@wsanville
Copy link
Contributor

The input apk you are running on has had file path shortening applied by Android Gradle plugin, yet you are running on a case insensitive filesystem. Redex's unpacker does not handle this case gracefully, and you'll either need to turn off the Gradle resource optimizations, or run Redex from a different OS like a Linux vm (or something like that). See https://jakewharton.com/smaller-apks-with-resource-optimization/ for some more info on the Gradle plugin behavior.

@wsanville wsanville closed this as not planned Won't fix, can't repro, duplicate, stale Aug 18, 2023
@shubhamguptadream11
Copy link
Author

shubhamguptadream11 commented Aug 19, 2023

Thanks.
I tried putting android.enableResourceOptimizations=false, by this it worked.
But this property is now deprecated and will no longer be available from AGP 8.0.0.
What can we do now then?
@wsanville

@wsanville
Copy link
Contributor

I do not have an ETA for you for when we can rework things to properly handle unpacking and reading the apk files on case insensitive filesystem. For now, a workaround that would suffice is to use a Linux VM.

facebook-github-bot pushed a commit that referenced this issue Aug 23, 2023
…stem

Summary: There have been several of these type issues #822 where the unpacker is given an .apk file with obfuscation already applied, and unpacking to a case insensitive filesystem results in things not lining up. Try to detect this with an error to make it more obvious.

Reviewed By: agampe

Differential Revision: D48488524

fbshipit-source-id: 68d6618e6cfde1d8e0a30b2c85e6b32340814ffe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants