Android Studio 3.1.X中導(dǎo)入項(xiàng)目的正確方法分享
前言
最近在使用Android Studio 3.1.2導(dǎo)入以前的項(xiàng)目遇到一些坑,借此機(jī)會(huì)把相關(guān)處理方法分享出來(lái)。
下面以導(dǎo)入Android Studio2.3.3項(xiàng)目為例:
在此之前先建議你用Android Studio 3.1.2創(chuàng)建一個(gè)新的項(xiàng)目,看看有哪些變化,這對(duì)你很有幫助。
修改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"
修改依賴(lài)關(guān)鍵字 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'
}
修改項(xiàng)目下的XXX(項(xiàng)目名)\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版本號(hào)保持一致
// 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改和當(dāng)前AS版本號(hào)一致。
修改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
這里告一段落,上面都改好之后同步項(xiàng)目(sync)。我為什么建議你把上面的都改好之后再同步,這樣省事兒,剛開(kāi)始的時(shí)候我也是改一點(diǎn)同步一下,問(wèn)題多且很浪費(fèi)時(shí)間,如果其中有些問(wèn)題沒(méi)能解決就容易走偏。
如果報(bào)錯(cuò):
<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報(bào)如下錯(cuò)誤請(qǐng)移步Android Studio 3.0后出現(xiàn)AAPT2和“android.enableAapt2”問(wèn)題以有解決方法
如果有這個(gè)錯(cuò)誤:這需要更新SDK,點(diǎn)擊藍(lán)色文字下載就好。
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
相關(guān)文章
Android Studio實(shí)現(xiàn)簡(jiǎn)易進(jìn)制轉(zhuǎn)換計(jì)算器
這篇文章主要為大家詳細(xì)介紹了Android Studio實(shí)現(xiàn)簡(jiǎn)易進(jìn)制轉(zhuǎn)換計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
Android Studio手動(dòng)配置Gradle的方法
Gradle:Gradle是一個(gè)基于Apache Ant和Apache Maven概念的項(xiàng)目自動(dòng)化建構(gòu)工具。它使用一種基于Groovy的特定領(lǐng)域語(yǔ)言(DSL)來(lái)聲明項(xiàng)目設(shè)置,拋棄了基于XML的各種繁瑣配置,本文給大家介紹Android Studio手動(dòng)配置Gradle的方法,一起看看吧2017-11-11
Android巧用ActionBar實(shí)現(xiàn)下拉式導(dǎo)航
這篇文章主要為大家詳細(xì)介紹了Android巧用ActionBar實(shí)現(xiàn)下拉式導(dǎo)航的相關(guān)資料,具有一定的實(shí)用性和參考價(jià)值,感興趣的小伙伴們可以參考一下2016-05-05
Android使用觀察者模式Observer實(shí)現(xiàn)網(wǎng)絡(luò)狀態(tài)監(jiān)聽(tīng)
這篇文章主要為大家詳細(xì)介紹了Android使用觀察者模式Observer實(shí)現(xiàn)網(wǎng)絡(luò)狀態(tài)監(jiān)聽(tīng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05
解決Android V7后自定義Toolbar、ActionBar左側(cè)有空白問(wèn)題
這篇文章主要介紹的Android V7后自定義Toolbar、ActionBar左側(cè)有空白問(wèn)題的解決方法,需要的朋友可以參考下2017-04-04
Android實(shí)現(xiàn)動(dòng)態(tài)顯示或隱藏密碼輸入框的內(nèi)容
這篇文章主要介紹了Android實(shí)現(xiàn)動(dòng)態(tài)顯示或隱藏密碼輸入框的內(nèi)容,主要通過(guò)設(shè)置EditText的setTransformationMethod()方法來(lái)實(shí)現(xiàn),需要的朋友可以參考下2014-09-09
掃二維碼下載apk并統(tǒng)計(jì)被掃描次數(shù)
本文主要對(duì)實(shí)現(xiàn)用戶(hù)掃描一個(gè)二維碼就能下載APP,并統(tǒng)計(jì)被掃描次數(shù)的方法進(jìn)行詳細(xì)介紹,具有一定的參考作用,下面跟著小編一起來(lái)看下吧2017-01-01
android開(kāi)發(fā)修改狀態(tài)欄背景色和圖標(biāo)顏色的示例
本篇文章主要介紹了android開(kāi)發(fā)修改狀態(tài)欄背景色和圖標(biāo)顏色的示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-01-01
玩轉(zhuǎn)AppBarLayout實(shí)現(xiàn)更酷炫的頂部欄
玩轉(zhuǎn)AppBarLayout,實(shí)現(xiàn)更酷炫的頂部欄,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09

