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

Material components dont work #7

Open
abhriyaroy opened this issue Sep 25, 2022 · 1 comment
Open

Material components dont work #7

abhriyaroy opened this issue Sep 25, 2022 · 1 comment

Comments

@abhriyaroy
Copy link

abhriyaroy commented Sep 25, 2022

As soon as I add material components dependency and set up a material widget (eg: Material button) inside the plugin app, the app crashes with the exception:


2022-09-25 15:15:29.319 10053-10053/com.malin.hook E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.malin.hook, PID: 10053
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.malin.plugin/com.malin.plugin.PluginAppCompatActivity}: android.view.InflateException: Binary XML file line #25 in com.malin.plugin:layout/plugin_activity: Binary XML file line #25 in com.malin.plugin:layout/plugin_activity: Error inflating class com.google.android.material.button.MaterialButton
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3707)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3864)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
        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:2253)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7870)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:550)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
     Caused by: android.view.InflateException: Binary XML file line #25 in com.malin.plugin:layout/plugin_activity: Binary XML file line #25 in com.malin.plugin:layout/plugin_activity: Error inflating class com.google.android.material.button.MaterialButton
     Caused by: android.view.InflateException: Binary XML file line #25 in com.malin.plugin:layout/plugin_activity: Error inflating class com.google.android.material.button.MaterialButton
     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:863)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1018)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:973)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1135)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1096)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:485)
        at com.malin.plugin.PluginAppCompatActivity.onCreate(PluginAppCompatActivity.java:24)
        at android.app.Activity.performCreate(Activity.java:8054)
        at android.app.Activity.performCreate(Activity.java:8034)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1347)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3688)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3864)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
        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:2253)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7870)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:550)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
     Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat (or a descendant).
        at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:243)
2022-09-25 15:15:29.319 10053-10053/com.malin.hook E/AndroidRuntime:     at com.google.android.material.internal.ThemeEnforcement.checkAppCompatTheme(ThemeEnforcement.java:213)
        at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:148)
        at com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.java:76)
        at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:229)
        at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:220)
        	... 27 more

@androidmalin
Copy link
Owner

androidmalin commented Sep 26, 2022

I add demo code in develop_kotlin branch, you can pull the latest code again.

detail:

pluginapk module add com.google.android.material:material:1.6.1
pluginapk module plugin_activity.xml add com.google.android.material.button.MaterialButton

bug fixed logic in pluginapk/src/main/java/com/malin/plugin/BaseActivity.java

            Field mThemeResourceField = contextClazz.getDeclaredField("mThemeResource");
            mThemeResourceField.setAccessible(true);
            mThemeResourceField.set(mContext, com.google.android.material.R.style.Theme_MaterialComponents_DayNight);
  1. ./make_plugin.sh make a plugin apk and copy to app/src/main/assets/ dir
  2. ./run.sh build host apk and install to your phone

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