这篇文章给大家分享的是有关Android Studio 3.1.X中如何导入项目的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
修改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
修改前:
<code class="language-html">// Top-level build file where you can add configuration options common to all sub-projects/modules. 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 }</code>
修改后:
// Top-level build file where you can add configuration options common to all sub-projects/modules. 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)。我为什么建议你把上面的都改好之后再同步,这样省事儿,刚开始的时候我也是改一点同步一下,问题多且很浪费时间,如果其中有些问题没能解决就容易走偏。
如果报错:
<code class="language-html">Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details </code>
修改gradle.properties,增加如下代码
android.enableAapt2=false
添加android.enableAapt2=false
报如下错误请移步Android Studio 3.0后出现AAPT2和“android.enableAapt2”问题以有解决方法
如果有这个错误:这需要更新SDK,点击蓝色文字下载就好。
感谢各位的阅读!关于“Android Studio 3.1.X中如何导入项目”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。