Android移動開發之【Android實戰項目】劍走偏鋒-得會導入別人的Android Studio項目!

1 前言

小白在學習的過程中難免會導入github上的hi項目學習,但是受到編譯器版本,sdk版本,各種api包版本不同,會遇到很多問題,本文不做過多修改配置文件-暴力展示了一下一種導入方法。

1 咔咔一頓刪除

首先:去到要導入項目的目錄下把.idea,*.iml,local.properties刪除(表示所有)
在這裏插入圖片描述
然後進入app文件夾同理把build,
.iml刪除
在這裏插入圖片描述

3 找到自己運行成功過的項目文件

接着打開已經run成功的項目的build.graid
在這裏插入圖片描述
把classpath:這整句複製,去要導入的項目中打開build.graid進行替換。

最後再打開gradle\wrapper\gradle-wrapper.properties複製最後一句,去到要導入的項目進行替換。

在這裏插入圖片描述
好了,最後可以打開android studio通過open an exisiting android studio project選項打開要導入的項目。

一般這樣都能run成功了並且app運行無異常,如果導入還是報錯,再根據具體錯誤進行修改或者百度。

4 解決過時API

Configuration 'compile' is obsolete and has been replaced with。。。。。。

例如:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    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'
    compile 'com.android.support:support-core-ui:25.3.1'
    compile 'com.android.support:design:25.3.1'
    testCompile 'junit:junit:4.12'
}

需要改成如下:
compile 改成implementation
androidTestCompile改成androidTestImplementation
testCompile 改成testImplementation
(裏面都是第三方庫-jar包)
在dependencies中用到了compile、testCompile、androidTestCompile、Provided、APK、Debug compile和Release compile 依賴方式,讓我們來看看他們有什麼區別:

1、compile:參與編譯,並且會打包到debug/release apk中。
2、testCompile:只參與單元測試編譯,不會打包到debug/release apk包中,不需要設備支持。
3、androidTestCompile:只參與UI測試編譯,不會打包到debug/release apk包中,需要設備支持。
4、Provided:只參與編譯,不會打包到debug/release apk中。
5、APK:不參與編譯,只會打包到debug/release apk中。
6、Debug compile:只參與debug編譯,只會打包到debug apk中。
7、Release compile:只參與release編譯,只會打包到release apk中。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章