ClassNotFoundException:"com.android.tools.fd.runtime.BootstrapApplication"

异常原因

使用AndroidStudio及API23打包并编译的APK,在部分机型上无法正常打开,会出现闪退现象.
连接调试可以发现程序报错提示没有找到类com.android.tools.fd.runtime.BootstrapApplication.

AndroidRuntime: FATAL EXCEPTION: main
Process: com.efamily.platform, PID: 26372
java.lang.RuntimeException: Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication: java.lang.ClassNotFoundException: Didn't find class "com.android.tools.fd.runtime.BootstrapApplication" on path: DexPathList[[zip file "/data/app/com.efamily.platform-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.efamily.platform-1, /vendor/lib, /system/lib]]

但是实际上我们并没有创建这个,明显是来自系统的.查了一下可以发现这个是跟AndroidStudio启用的一个叫Instant Run的功能有关.


Instant Run

根据官方文档说明:

Although your first build may take longer to complete, Instant Run pushes subsequent updates to your app without building a new APK, so changes are visible much more quickly.
尽管第一次build的时间会花费更长的时间,但是Instant Run可以在后续更新APP时不需要创建新的APK,所以改变是快速可见的.


Instant Run的缺陷

在测试的时候对代码进行修改时,再运行会很快打开当前已经打开的Activity并更新内容(当修改UI时会非常明显).更新APK的速度确实是会非常快.但是他的缺点也是很明显的:

Instant Run is supported only when you deploy the debug build variant, use Android Plugin for Gradle version 2.0.0 or higher, and set minSdkVersion to 15 or higher in your app’s module-level build.gradle file. For the best performance, set minSdkVersion to 21 or higher.
首先只有使用Gradle 2.0以上版本可用,最低minSdkVersion必须是15或者以上,需要得到更好体验应该设置SDK 21以上.另外,只会在部署变化的调试版本时支持
(部分翻译有误请指出)

所以这就说明了当系统API并没有达到21时非常有可能是无法支持的.虽然在实际中不能用的机子有一部分是5.0系统的,但并没有什么卵用…


解决方案

解决方案是建议在发部测试版本的时候如果测试的机子系统覆盖范围比较大(包括很多低版本系统时),可以关闭该功能并重新打包发布即可.
官方说明关闭方法如下:

To disable Instant Run:

  • Open the Settings or Preferences dialog.
  • Navigate to Build, Execution, Deployment > Instant Run.
  • Uncheck the box next to Enable Instant Run.
    打开设置->Build->Execution->Deployment->Instant Run->取消Enable即可

我在我的Android Studio上并没有发现这个结构层次,建议用以下的办法会更容易也比较适用所有类型的Android Studio

  • 打开Preferences或者Settings
  • 在左上角搜索框中搜索Instant Run
  • 左侧边选择Instant Run选项,选择第一个Enable取消打勾

我的选项显示的是:

Enable Instant Run to hot swap code/resource changes on deploy(default enabled)


官方文档

https://developer.android.com/studio/run/index.html#instant-run
可能需要翻墙才能看

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值