Instant run doesn't work due to “multiple process”

后端 未结 3 1119

After having configured instant run, the run button has a small yellow thunderbolt.But while I run the app, Android Studio still performed a full build & install, full messa

3条回答
  •  时光说笑
    2021-02-08 04:31

    I ran into this problem when running ProcessPhoenix. Instead of disabling it completely, I just disabled it for my debug build.

    Instead of compile I use
    releaseCompile 'com.jakewharton:process-phoenix:2.0.0'

    And to not break the build I use reflection to trigger the application process restart:

    try {
        Class clazz = Class.forName("com.jakewharton.processphoenix.ProcessPhoenix");
        Method triggerRebirthMethod = clazz.getMethod("triggerRebirth", Context.class);
        triggerRebirthMethod.invoke(this, new Object[]{getActivity()});
    } catch (Exception e) {
        // Exception handling
    }
    

    So now I can still use Instant Run and keep the lib included. :)

    (Of course, reflection is never ideal, but the app process restart is only used in one rare particular case in the app.)

提交回复
热议问题