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

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

内容简介:使用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 导入项目的正确姿势》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

自己动手做iOS App

自己动手做iOS App

张子怡 / 电子工业出版社 / 2017-8 / 69.00

《自己动手做iOS App:从设计开发到上架App Store》为想要接触iOS 应用设计、开发的读者提供了由浅入深的详细指导。从iOS 应用制作的步骤是什么,应该使用什么软件,如何发布应用到App Store,到iOS 的设计理念是什么,如何正确书写Swift 语言,再到后端和客户端是如何交互运作的等,本书配合图示,精辟、直观地阐明了iOS 应用制作中的种种疑问。 如果你是一位第一次接触i......一起来看看 《自己动手做iOS App》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换