由于 "multiple process",Instant 运行 无法使用
Instant run doesn't work due to "multiple process"
配置即时 运行 后,运行 按钮有一个小黄色 thunderbolt.But 而我 运行 应用程序,Android Studio 仍然执行完整的构建和安装,图片中列出了完整的消息。
我在http://tools.android.com/tech-docs/instant-run里找了官方文档,没有关于"multiple process"的任何内容。我不知道"multiple processes"是编译还是我的android应用程序。
我应该配置什么来关闭多个进程并体验即时运行?
您的应用未启用 Instant 运行,因为它使用了多个进程。
如 Android 工具项目网站 (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."
因此,要体验即时 运行,您必须确保您的应用未使用多个进程。为此检查您的 AndroidManifest.xml。
可能是多进程使用来自导入库。例如,LeakCanary 使用多个进程,在它自己的 AndroidManifest.xml 中定义。查找定义位置的最佳方法是搜索整个项目(Android Studio on OS X 中的 Cmd-Shift-F)以查找 "android:process".
我运行在运行ProcessPhoenix的时候遇到了这个问题。我没有完全禁用它,而是为我的调试版本禁用了它。
我使用
而不是 compile
releaseCompile 'com.jakewharton:process-phoenix:2.0.0'
为了不破坏构建,我使用反射来触发应用程序进程重启:
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
}
所以现在我仍然可以使用 Instant 运行 并保留包含的库。 :)
(当然,反射从来都不是理想的,但app进程重启只是在app中一种罕见的特殊情况下使用。)
我尝试了很多...快速的解决方案是在开发时删除 android:process=":remote"..
但这还不够..试试下面的方法。
- 使用风味。
build.gradle(应用程序)
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"
现在你有 4 个 Build Variants
=> developmentDebug, developmentRelease, productionDebug, productionRelease
developmentDebug, developmentRelease
=> 不使用多进程
productionDebug, productionRelease
=> 使用多进程
2.将原来的"AndroidManifest.xml"复制到YouAppRoot\app\src\production,然后删除除'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>
- 从原始 AndroidManifest.xml 中删除 android:process=":remote" 行
- 现在您可以像下面这样检查。
配置即时 运行 后,运行 按钮有一个小黄色 thunderbolt.But 而我 运行 应用程序,Android Studio 仍然执行完整的构建和安装,图片中列出了完整的消息。
我在http://tools.android.com/tech-docs/instant-run里找了官方文档,没有关于"multiple process"的任何内容。我不知道"multiple processes"是编译还是我的android应用程序。
我应该配置什么来关闭多个进程并体验即时运行?
您的应用未启用 Instant 运行,因为它使用了多个进程。
如 Android 工具项目网站 (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."
因此,要体验即时 运行,您必须确保您的应用未使用多个进程。为此检查您的 AndroidManifest.xml。
可能是多进程使用来自导入库。例如,LeakCanary 使用多个进程,在它自己的 AndroidManifest.xml 中定义。查找定义位置的最佳方法是搜索整个项目(Android Studio on OS X 中的 Cmd-Shift-F)以查找 "android:process".
我运行在运行ProcessPhoenix的时候遇到了这个问题。我没有完全禁用它,而是为我的调试版本禁用了它。
我使用
而不是 compile
releaseCompile 'com.jakewharton:process-phoenix:2.0.0'
为了不破坏构建,我使用反射来触发应用程序进程重启:
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
}
所以现在我仍然可以使用 Instant 运行 并保留包含的库。 :)
(当然,反射从来都不是理想的,但app进程重启只是在app中一种罕见的特殊情况下使用。)
我尝试了很多...快速的解决方案是在开发时删除 android:process=":remote"..
但这还不够..试试下面的方法。
- 使用风味。
build.gradle(应用程序)
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"
现在你有 4 个 Build Variants
=> developmentDebug, developmentRelease, productionDebug, productionRelease
developmentDebug, developmentRelease
=> 不使用多进程
productionDebug, productionRelease
=> 使用多进程
2.将原来的"AndroidManifest.xml"复制到YouAppRoot\app\src\production,然后删除除'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>
- 从原始 AndroidManifest.xml 中删除 android:process=":remote" 行
- 现在您可以像下面这样检查。