Instant run doesn't work due to "multiple process"

2.9k views Asked by At

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 ?

3

There are 3 answers

6
Jannik On BEST ANSWER

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

2
Roy Solberg On

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

0
Soo Chun Jung On

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