Android移动开发之【Android实战项目】剑走偏锋-得会导入别人的Android Studio项目!
1 前言
小白在学习的过程中难免会导入github上的hi项目学习,但是受到编译器版本,sdk版本,各种api包版本不同,会遇到很多问题,本文不做过多修改配置文件-暴力展示了一下一种导入方法。
1 咔咔一顿删除
首先:去到要导入项目的目录下把.idea,*.iml,local.properties删除(表示所有)
然后进入app文件夹同理把build,.iml删除
3 找到自己运行成功过的项目文件
接着打开已经run成功的项目的build.graid
把classpath:这整句复制,去要导入的项目中打开build.graid进行替换。
最后再打开gradle\wrapper\gradle-wrapper.properties复制最后一句,去到要导入的项目进行替换。
好了,最后可以打开android studio通过open an exisiting android studio project选项打开要导入的项目。
一般这样都能run成功了并且app运行无异常,如果导入还是报错,再根据具体错误进行修改或者百度。
4 解决过时API
Configuration 'compile' is obsolete and has been replaced with。。。。。。
例如:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:support-core-ui:25.3.1'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
}
需要改成如下:
compile 改成implementation
androidTestCompile改成androidTestImplementation
testCompile 改成testImplementation
(里面都是第三方库-jar包)
在dependencies中用到了compile、testCompile、androidTestCompile、Provided、APK、Debug compile和Release compile 依赖方式,让我们来看看他们有什么区别:
1、compile:参与编译,并且会打包到debug/release apk中。
2、testCompile:只参与单元测试编译,不会打包到debug/release apk包中,不需要设备支持。
3、androidTestCompile:只参与UI测试编译,不会打包到debug/release apk包中,需要设备支持。
4、Provided:只参与编译,不会打包到debug/release apk中。
5、APK:不参与编译,只会打包到debug/release apk中。
6、Debug compile:只参与debug编译,只会打包到debug apk中。
7、Release compile:只参与release编译,只会打包到release apk中。
上一篇: 验证码机制与实现