eleme / Amigo

A hotfix library for Android platform, and not just this...
Other
1.36k stars 213 forks source link

Here is a bug with activity-alias #213

Closed yang747046912 closed 7 years ago

yang747046912 commented 7 years ago

Here's how to review bug with demo

first. in AndroidManifest

<activity
            android:name=".TestPatchedActivities"
            android:screenOrientation="portrait"/>
        <activity-alias
            android:name="ele.aaa.ele"
            android:targetActivity=".TestPatchedActivities">
            <intent-filter>
                <action android:name="ele.aaa.ele"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity-alias>

Second. startactivity

public void testPatchedActivities(View v) {
        startActivity(new Intent("ele.aaa.ele").putExtra("test", new
                ParcelBean("jack", 1)));
    }

Third. gradle runHost and gradlew preparePatch ,then let the patch effect

Fourth. click Test patched activity then the app will crash.

FATAL EXCEPTION: main Process: me.ele.app.amigo, PID: 29413 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{me.ele.app.amigo/ele.aaa.ele}: java.lang.ClassNotFoundException: Didn't find class "ele.aaa.ele" on path: DexPathList[[dex file "/data/data/me.ele.app.amigo/files/amigo/3384999164/dexes/classes.dex"],nativeLibraryDirectories=[/data/data/me.ele.app.amigo/files/amigo/3384999164/libs, /vendor/lib64, /system/lib64]] at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2371) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524) at android.app.ActivityThread.access$800(ActivityThread.java:167) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1417) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5536) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750) Caused by: java.lang.ClassNotFoundException: Didn't find class "ele.aaa.ele" on path: DexPathList[[dex file "/data/data/me.ele.app.amigo/files/amigo/3384999164/dexes/classes.dex"],nativeLibraryDirectories=[/data/data/me.ele.app.amigo/files/amigo/3384999164/libs, /vendor/lib64, /system/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) at me.ele.amigo.AmigoClassLoader.loadClass(AmigoClassLoader.java:64) at android.app.Instrumentation.newActivity(Instrumentation.java:1070) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2361) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524)  at android.app.ActivityThread.access$800(ActivityThread.java:167)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1417)  at android.os.Handler.dispatchMessage(Handler.java:111)  at android.os.Looper.loop(Looper.java:194)  at android.app.ActivityThread.main(ActivityThread.java:5536)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)  Suppressed: java.lang.ClassNotFoundException: ele.aaa.ele at java.lang.Class.classForName(Native Method) at java.lang.BootClassLoader.findClass(ClassLoader.java:781) at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) at java.lang.ClassLoader.loadClass(ClassLoader.java:504) ... 14 more Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

after work hard with Agmio ,I find the crash reason and fix it . This is the code (in AmigoCallback 84 line ). Is it all right? @JackCho

if ((newActivityInfo = ActivityFinder.getActivityInfoInNewApp(context,
                        activityName)) != null) {
                    // TODO check intent filter ?
                    FieldUtils.writeDeclaredField(msg.obj, "activityInfo", newActivityInfo);
                    intent.setComponent(new ComponentName(context,newActivityInfo.name));
                }
JackCho commented 7 years ago

pr has been merged into master. we will release new version ASAP.

yang747046912 commented 7 years ago

The latest code seems to not working. It will still crash。

JackCho commented 7 years ago

issue has been fixed, just because we hasn't released the new Amigo version yet

JackCho commented 7 years ago

@yang747046912 please use 0.6.5 version, and add my personal maven url temporarily

buildscript {
    repositories {
        jcenter()
       maven {
            url "https://dl.bintray.com/jackcho/maven"
        }
    }

    dependencies {
        classpath 'me.ele:amigo:0.6.5'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://dl.bintray.com/jackcho/maven"
        }
    }
}
yang747046912 commented 7 years ago

I use the source code in master branch to test this problem and it crashed!!

JackCho commented 7 years ago

paste crash log please

yang747046912 commented 7 years ago

FATAL EXCEPTION: main Process: me.ele.app.amigo, PID: 4432 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{me.ele.app.amigo/ele.aaa.ele}: java.lang.ClassNotFoundException: Didn't find class "ele.aaa.ele" on path: DexPathList[[dex file "dalvik.system.DexFile@429e68c8"],nativeLibraryDirectories=[/data/data/me.ele.app.amigo/files/amigo/4183123031/libs, /vendor/lib, /system/lib]] at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2367) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2521) at android.app.ActivityThread.access$800(ActivityThread.java:172) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:5468) 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:860) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:676) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassNotFoundException: Didn't find class "ele.aaa.ele" on path: DexPathList[[dex file "dalvik.system.DexFile@429e68c8"],nativeLibraryDirectories=[/data/data/me.ele.app.amigo/files/amigo/4183123031/libs, /vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:497) at java.lang.ClassLoader.loadClass(ClassLoader.java:457) at me.ele.amigo.AmigoClassLoader.loadClass(AmigoClassLoader.java:64) at android.app.Instrumentation.newActivity(Instrumentation.java:1061) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2521)  at android.app.ActivityThread.access$800(ActivityThread.java:172)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)  at android.os.Handler.dispatchMessage(Handler.java:110)  at android.os.Looper.loop(Looper.java:193)  at android.app.ActivityThread.main(ActivityThread.java:5468)  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:860)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:676)  at dalvik.system.NativeStart.main(Native Method) 

just like the Fourth step

JackCho commented 7 years ago

462b3f solved this issue, please check again

JackCho commented 7 years ago

@yang747046912 please help to check whether your issue is solved or not

yang747046912 commented 7 years ago

@JackCho yes, with the last code ,it will not crash. thanks.