说明:
安卓开发编译时候运行一起正常,但是打包或者拷贝编译过的包安装,app打不开,报错:
java.lang.RuntimeException: Unable to instantiate application
原因:
根目录下的build.gradle的classpath为最新的2.3.3会报这个错
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }
节约:
classpath版本改小一点:改成2.2.3。
如果:改成2.1.3则会运行编译不通过,会报错:
所以最终代码:
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }
总结:这样,你所打的包,发布给别人就能装上了。应该是gragle打包的问题,以后sdk应该就会自动修复了。