在这里不得不吐槽一下google,由于新的Android studio3版本出来了,然后也摒弃了Android2.3版本,导致现在我的Android2.3.3出问题提示下载配件也失效了,还有就是依赖项目的新模式从compile变成了implementation也给我们这些程序猿额外的任务,升级公司的旧项目的版本。 在这里我就来说说我升级项目版本的经历过的坑。
新建project工程命名为LinApp:import module然后添加到新项目,因为Android studio 3.1.x版本不自动导入编译列表的问题见:
Android Studio 3.1 import new module找不到解决方法
当成功playeroperator成为运行项目时也出现了新的错误提醒
红色的字所表达的意思就是编译工具版本过于老旧,需要更新工具版本并且同步项目,点击update build tools version and sync project,一个个更新下来,提醒:
这边所表达的意思就是依赖方式的变化,蓝色网址为详细说明,Android studio3版本以前都是 采用
1.testCompile方式,而现在这边提示要修改为testImplementation
2.compile方式,而现在这边提示要修改为implementation
3.androidTestCompile方式,而现在这边提示要修改为androidTestImplementation
上述说明了了修正提示,至于修改方式则直接:ctrl+R键进行文本替换
1.直接compile的单条数据进行Replace
2直接大写Compile的单条数据进行Replace,这里主要针对的是androidTestCompile等的后缀
注意事项:不要使用Replace all因为路径里面可能存在compile,要一条一条看着换过去,如下:
最后就编译成功通过,可以运行项目到手机上。
全部按提示替换依赖字母后
Could not resolve all dependencies for configuration ':playeroperator:debugRuntimeClasspath'.
Could not determine artifacts for com.android.support:support-compat:27.1.1: No cached version available for offline mode
当场斯巴达了,简直是有没有搞错了是吧,表示深深的鄙视有没有
出现原因往往是依赖library的compile没有完全转变或者以下自动生成依赖没有按最新版本修正
原因就出来compile依赖个人库没有处理
---------------当然为了完全符合新版本规范,删除
buildToolsVersion '27.0.3'
最后成功运行编译到手机上:
个人library build.gradle配置更新
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
// implementation fileTree(include: ['*.jar'], dir: 'libs')
// androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
// exclude group: 'com.android.support', module: 'support-annotations'
// })
// implementation 'com.android.support:appcompat-v7:27.1.1'
// testImplementation 'junit:junit:4.12'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.+'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'org.xutils:xutils:3.4.0'
implementation files('libs/gson-2.2.4.jar')
//implementation 'com.google.code.gson:gson:2.8.0'//懒得换最新
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
//准备移除
implementation 'com.bigkoo:convenientbanner:2.0.5'
// 轮播图
implementation 'com.github.bumptech.glide:glide:4.0.0-RC1'
implementation 'com.android.support:support-v4:27.1.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0-RC1'
}
playeroperator build.gradle新旧版本配置
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.playeroperator"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
repositories {//不知用途,给glide顺带的
mavenCentral() // jcenter() works as well because it pulls from Maven Central
}
}
dependencies {
//------依赖方式--Android studio3.1 新的--开始---------------
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':librarypo')
implementation project(':ffmpeg4android_lib')
implementation 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
//-------------------内存泄漏检测工具(开始)---------------------
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.1'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
//-------------------内存泄漏检测工具(结束)---------------------
//------依赖方式--Android studio3.1 新的--结束---------------
//------依赖方式--Android studio2 以前--开始---------------
// compile fileTree(include: ['*.jar'], dir: 'libs')
// 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'
// testCompile 'junit:junit:4.12'
// compile project(':librarypo')
// compile 'com.jakewharton:butterknife:8.5.1'
// annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
// //-------------------内存泄漏检测工具(开始)---------------------
// debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
// releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
// testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
// //-------------------内存泄漏检测工具(结束)---------------------
//------依赖方式--Android studio2 以前--结束---------------
}
最后总结:
1.新建工程import module公司项目进工程
2.settings.gradle将工程写入编译列表
3.各种点击update build tool,按照Android studio提示来,按照新标准删除buildToolsVersion 'x.x.x'
4.复制新工程的自动生成依赖包,到library和公司module,替换原本的自动生成依赖包;
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
5.compile,Compile替换旧的build.gradle,然后同步
6.如果出现问题不用担心,在logcat里面点击找到对应的漏修改的位置
7.最后运行编译成功到手机上,我们的项目就直接转变为Android studio3的格式标准了
注意:
implement(特殊,让依赖包的一些东西保护起来)
概念 : 将该依赖隐藏在内部,而不对外部公开。
理解 :类似于private私有,这里是只有本module可以用,就算依赖用不了它依赖或者封装的东西
举例 : 此时项目中有一个 mudule
是 ImageLoader
,其内部用 implement
指令依赖了 glide
这个库, 那么此时我们在 app mudule 中无法调用 glide 库中的方法.
compile
概念: android studio 3.0 版本后废弃该指令 改用 api
代替, api
完全等同于之前的 compile
指令, 也就是普通的依赖, 第三方库在 mudule
中依赖后其他 mudule
都可以使用该库.
官方推荐在不影响的前提下优先使用 implement
指令依赖.
一. api是complie的替代品,api 与 complie 没有区别。
二. 最新官方推荐 implementation 用来代替 compile, implementation 会使AS编译速度更快。
三. implementation声明的依赖包只限于模块内部使用,不允许其他模块使用。
也就是说:模块自己用的依赖声明用:implementation,允许别的模块调用的用:api。这个既要编译速度快,也要区分好!!!不然你的主module会各种找不到其它module里的依赖。
是不是满满的成就感,嘿嘿