Android Studio 3.1.X 导入项目的正确姿势

栏目: 编程工具 · Android · 发布时间: 7年前

内容简介:使用Android Studio 3.1.2导入以前的项目遇到一些坑,借此机会把相关处理方法分享出来。下面以导入Android Studio2.3.3项目为例:在此之前先建议你用Android Studio 3.1.2创建一个新的项目,看看有哪些变化,这对你很有帮助。

使用Android Studio 3.1.2导入以前的项目遇到一些坑,借此机会把相关处理方法分享出来。

下面以导入Android Studio2.3.3项目为例:

在此之前先建议你用Android Studio 3.1.2创建一个新的项目,看看有哪些变化,这对你很有帮助。

修改app\build:gradle

  • 修改compileSdkVersion和buildToolsVersion

修改前,

compileSdkVersion 23
buildToolsVersion '25.0.0'

修改后:

compileSdkVersion 27
buildToolsVersion '27.0.3'

其中buildToolsVersion 是在Android Studio 3.0之后取消了,你可以保留也可以注释掉,

在defaultConfig方法中将targetSdkVersion 为27并增加一下代码。

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  • 修改依赖关键字 compile(implementation/api),provided(compileOnly),apk(runtimeOnly)

修改前:

dependencies {

    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile name: 'SMSSDK-3.0.0', ext: 'aar'
    compile name: 'SMSSDKGUI-3.0.0', ext: 'aar'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:recyclerview-v7:23.4.0'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.youth.banner:banner:1.4.9'
    compile 'com.facebook.fresco:fresco:0.13.0'
    compile 'com.squareup.okhttp3:okhttp:3.4.1'
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.foamtrace:photopicker:1.0'
    compile 'com.github.chrisbanes.photoview:library:1.2.4'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile project(':ZXingAndroid')
    compile 'com.google.zxing:core:3.3.1'
}

修改后:

dependencies {

    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.1'
    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 name: 'SMSSDK-3.0.0', ext: 'aar'
    implementation name: 'SMSSDKGUI-3.0.0', ext: 'aar'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'de.hdodenhof:circleimageview:2.1.0'
    implementation 'com.youth.banner:banner:1.4.9'
    implementation 'com.facebook.fresco:fresco:0.13.0'
    implementation 'com.squareup.okhttp3:okhttp:3.4.1'
    implementation 'com.google.code.gson:gson:2.8.0'
    implementation 'com.github.bumptech.glide:glide:3.7.0'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.foamtrace:photopicker:1.0'
    implementation 'com.github.chrisbanes.photoview:library:1.2.4'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.zxing:core:3.3.1'
}

修改项目下的XXX(项目名)\build:gradle

修改前:

buildscript {
    repositories {
    jcenter()
} dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'

    // NOTE: Do not place your application odependencies here; they belong
    // in the individual module build.gradle files
   }
}

allprojects {
    repositories {
        jcenter()
        maven {url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

修改后:

buildscript {
    repositories {
         google()
         jcenter()
    }
    dependencies {
         classpath 'com.android.tools.buiwld:gradle:3.1.3'//与AS版本号保持一致

         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
         google()
         jcenter()
         maven { url "https://jitpack.io" }
    }
}
task clean(type: Delete) {
     delete rootProject.buildDir
}

repositories方法中都增加了google(),build:gradle改和当前AS版本号一致。

修改gradle-wrapper.properties

修改前:

#Tue Aug 29 08:07:34 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

修改后:

#Tue Aug 29 08:07:34 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

主要修改了:distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

这里告一段落,上面都改好之后同步项目(sync)。我为什么建议你把上面的都改好之后再同步,这样省事儿,刚开始的时候我也是改一点同步一下,问题多且很浪费时间,如果其中有些问题没能解决就容易走偏。

如果报错:

Error: java.util.concurrent.ExecutionException:
com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details

修改gradle.properties,增加如下代码

android.enableAapt2=false

添加android.enableAapt2=false报如下错误请移步 Android Studio 3.0后出现AAPT2和“android.enableAapt2”问题以有解决方法

Android Studio 3.1.X 导入项目的正确姿势

如果有这个错误:这需要更新SDK,点击蓝色文字下载就好。

Android Studio 3.1.X 导入项目的正确姿势


以上所述就是小编给大家介绍的《Android Studio 3.1.X 导入项目的正确姿势》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

计算复杂性

计算复杂性

阿罗拉 巴拉克 / 骆吉洲 / 机械工业出版社 / 2016-1-1 / 129元

《计算复杂性的现代方法》是一部将所有有关复杂度知识理论集于一体的教程。将最新进展和经典结果结合起来,是一部很难得的研究生入门级教程。既是相关科研人员的一部很好的参考书,也是自学人员很难得的一本很好自学教程。本书一开始引入该领域的最基本知识,然后逐步深入,介绍更多深层次的结果,每章末都附有练习。对复杂度感兴趣的人士,物理学家,数学家以及科研人员这本书都是相当受益。一起来看看 《计算复杂性》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具