Android Studio module从2.3升级到3.1的详细过程处理,让公司项目直接匹配最新studio3模式

在这里不得不吐槽一下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的格式标准了


是不是满满的成就感,嘿嘿







猜你喜欢

转载自blog.csdn.net/insist_hui/article/details/80842522
今日推荐