Android Studio匯入github專案詳解
最近在群裡發現總有人問一些關於Android Studio的問題,Android Studio是Google新出的一款IDE工具,它是基於Intellij IDEA開發的,AS開發Android很方便,那麼今天就說一下怎麼將Github的專案匯入Android Studio中而不報錯,完美執行。Github上的專案大部分是基於Gradle編譯的,而gradle線上下載是下不了的,除非你翻牆,買了自己的vpn,就不需要以下的操作了,可以直接忽略過,直接匯入github專案,然後Fix Project坐等就ok。如果你沒有vpn,沒有翻牆,那麼下面請看好我是怎麼匯入一個github專案的。
首先我在github上下載一個專案,就以RippleEffect
為例吧,首先我先下載這個壓縮包,或者你也可以直接在AS中checkout該專案。
然後我們開啟AS,新建一個預設的Android module
看一下我們的兩個專案的結構目錄
我們可以看到github上下載的專案中是有library的,我們自己新建的是沒有,這個library是和eclipse中的library一樣的,依賴庫。
然後我們要改幾個檔案,重點來了:
第一個檔案:
根目錄下的build.gradle,看看我們新建的專案中
// 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:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
build:gradle:1.3.0而我們下載的專案的版本是1.2.3
// 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:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
if (hasProperty("VERSION_NAME")) {
version = VERSION_NAME
group = GROUP
}
repositories {
jcenter()
}
}
把下載的github的專案中的build.gradle改成我們的版本
第二個檔案:
gradle資料夾下的gradle-wrapper.properties檔案
下載的專案是
#Mon Dec 01 21:42:38 CET 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
專案的gradle版本是2.2.1,而我們的本地gradle版本是2.4,改成我們本地的
第三個檔案:app目錄下的build.gradle檔案
本地的sdk編譯版本是23,buildtools版本是23.0.1
最小sdk版本是15,app版本是1---------
第三方依賴庫是v7-23.0.1,junit-4.12
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.hankkin.myapplication"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
}
這個第三方依賴庫可以倒進專案之後再更改
然後我們把library中build.gradle中的最後一行
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
註釋掉,compilesdkversion,buildtoolsversion也改成我們本地用的,當然在AS中改也是可以的
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 22
versionCode 9
versionName "1.3"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
好了下面我們開始導專案
開啟AS,選擇import project,找導下載的RippleEffect,坐等gradle編譯
編譯成功我們開啟專案看一下
開啟project structure修改版本和依賴包
執行一下:
![](https://i.iter01.com/images/4a968a80f91d52fc6243e34968c3ea6c1103e281bedde41805dfcc29495b64f7.png)
相關文章
- android studio匯入專案--解決gradle-headache問題AndroidGradle
- Android Studio 專案匯入的正確姿勢Android
- IDEA如何匯入專案,包括從git倉庫(github)匯入專案IdeaGithub
- vercel無法匯入github專案Github
- 解決Android Studio每次匯入專案都會下載Gradle和Android Gradle plugin的問題AndroidGradlePlugin
- Android Studio匯入原始碼Android原始碼
- Android Studio 匯入 AOSP 原始碼Android原始碼
- Android studio匯出apk檔案AndroidAPK
- Android專案匯入高德地圖Android地圖
- Android Studio專案匯入之後出錯:Error:(1, 0) Plugin with id 'com.android.application' not found.AndroidErrorPluginAPP
- Android Studio 新特性詳解Android
- Android Studio打包專案:APKAndroidAPK
- 【Android Studio】解決升級 macOS High Sierra 後 Android Studio 同步專案時 gradle 構AndroidMacGradle
- 怎麼在Android專案中匯入ffmpeg庫?Android
- Android Studio Gradle 常用配置詳解AndroidGradle
- 【Android Studio】入門系列 3.建或匯入APPAndroidAPP
- [轉]Android Studio匯入工程報錯 Error:Cause: peer not authenticated 解決方案AndroidError
- java怎麼匯入專案?java已有專案如何匯入eclipse?JavaEclipse
- IDEA匯入Eclipse專案IdeaEclipse
- Pycharm匯入python專案PyCharmPython
- 使用命令列建立Android Studio專案命令列Android
- Android Studio修改專案名和包名Android
- Android Studio在android Emulator中執行的專案黑屏Android
- 將AOSP原始碼匯入到Android Studio進行檢視原始碼Android
- eclipse專案匯入到IDEAEclipseIdea
- IDEA匯入SpringBoot專案教程IdeaSpring Boot
- Android輸入事件詳解Android事件
- IDEA匯入專案筆記二Idea筆記
- qtDesignerStudio 生成 cmake 專案匯入 qtcreatorQT
- Android Studio “Project Structure”選專案錄中的Android選項丟失及解決辦法AndroidProjectStruct
- Python入門小專案-氣泡排序詳解Python排序
- Laravel 專案如何實現 GitHub 登入LaravelGithub
- Android Studio向專案新增C/C++原生程式碼AndroidC++
- Android Studio 已有專案新增NDK支援(mac/ndk-build)AndroidMacUI
- maatwebsite/excel3.1 匯入Excel詳解WebExcel
- Android Studio jni - 入門篇Android
- 【Android Studio】解決 Android Studio2.2 無法輸入中文標點符號的問題Android符號
- IDEA匯入專案有個小JIdea
- idea匯入專案報Maven version is not definedIdeaMaven