Instant run doesn't work due to "multiple process"
Asked Answered
M

3

11

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 message is listed in the picture.

I've searched the official documents in http://tools.android.com/tech-docs/instant-run , but there wasn't anything about "multiple process".I wonder "multiple processes" means compiling or my android app.

What should I configure to turn off multiple processes and experience instant run ?

Mond answered 28/2, 2016 at 8:23 Comment(0)
M
9

Instant Run is not enabled for your app because it is using multiple processes.

As stated on the Android Tools Project Site (http://tools.android.com/recent/androidstudio20beta6availableinthecanarychannel):

"Apps that were using multiple processes (via android:process in the manifest) were not being updated properly with Instant Run. For the time being, we have turned off Instant Run in such a scenario."

Hence, to experience instant run, you must ensure your app isn't using multiple processes. Check your AndroidManifest.xml for this.

It may be that the multiple process usage comes from an imported library. LeakCanary, for example, uses multiple processes, defined in its own AndroidManifest.xml. The best way to find where this is defined is to search your entire project (Cmd-Shift-F in Android Studio on OS X) for "android:process".

Maryellen answered 29/2, 2016 at 14:49 Comment(6)
I needed to remove LeakCanary and ProcessPhoenix from my app to get around this. Those were the culprits. Also, it's worth noting that I've been told this is fixed and will be released in AS 2.0.0-beta7.Orvalorvan
Good work! Thanks for the update, will be good if this gets fixed in the next release.Maryellen
Sorry to be late here. My later conclusion is the same as your answer. Thanks~Mond
Now this is fixed, but Instant Run now restarts the whole app in case of changes because of this. AS version 2.2.3Tung
Does anyone know how to find the library who uses multiple process? Cmd-Shift-F only searches local, but my libraries are all with "compile". So no source available.Floating
@MaxMakeichik What do you mean by "Now this is fixed", if a full build/restart of the whole app is still occurring?Maryellen
M
7

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.)

Marcos answered 5/7, 2017 at 17:0 Comment(2)
Remember to exclude from proguard if using in release builds!Furman
Using reflection worked well. But it stopped working for my app. I think it may be because we switched to using App Bundles, or some other build tool update that is stripping out the ProcessPhoenix code.Pedagogue
P
1

I tried a lot... and quick solution is to remove android:process=":remote" when developing..

but that's not enough.. try bellow.

  1. use Flavors.

build.gradle(app)

buildTypes {
    debug {   
        minifyEnabled false
        signingConfig signingConfigs.debug
    }

    release {
        minifyEnabled true
        signingConfig signingConfigs.release
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
productFlavors {
    development {
        minSdkVersion 21
    }
    production {
        minSdkVersion 14
    } 
}
flavorDimensions "default"


Now you have 4 Build Variants
=> developmentDebug, developmentRelease, productionDebug, productionRelease



developmentDebug, developmentRelease
=> no use multi process

productionDebug, productionRelease
=> use multi process



2. copy orginal "AndroidManifest.xml" to YouAppRoot\app\src\production, and then remove all elements except 'service'.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:installLocation="auto">

<application
    android:name=".App"
    android:allowBackup="true"
    android:hardwareAccelerated="@bool/gpu_enabled"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:theme="@style/MyTheme">

    <service
        android:name=".xxxx.MyService"
        android:exported="false"
        android:process=":remote">
        <intent-filter>
            <action android:name="xxxx.test.aaa" />
        </intent-filter>
    </service>
</application>

  1. remove android:process=":remote" line from original AndroidManifest.xml

  2. now you can check like below.

enter image description here

Polyester answered 7/6, 2018 at 8:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.