如何将 Github 非 Android Studio 项目作为库导入 Android Studio?
How to Import Github non Android Studio Project as library into Android Studio?
我正在尝试导入 standout library,这是一个 github 项目作为我的 project.What 中的库,我试过如下:
在我的根项目目录中创建了一个名为 'libs'
的文件夹
- 已将 git 上 Standout 项目的完整文件夹 'library' 复制到 'libs'
- 重命名了我刚刚复制到的文件夹 'library',例如"standout"(只是为了避免混淆)
现在使用以下命令将此库添加到我的 settings.gradle
中:
包括':libs:standout'
转到我的 AppProject 的 build.gradle
文件并将以下行添加到我的 'dependencies':
编译项目(':libs:standout')
但是我得到了错误然后像这样添加
compile fileTree(dir: 'libs', include: ['standout'])
gradle同步成功但是库项目的src文件上有红色标记。。
我无法从MainActivity访问库src文件我的 Project.As github 项目不是 android studio 项目,我需要为此做任何额外的事情吗?
我尝试了 Wesley 建议的以下方法:
Download or clone the git repository, copy the library
folder into
your project root folder.
Then in your project settings.gradle
file, add a ':library'
at the
end of the include line, like this: include ':app', ':library'
, then
gradle sync
your whole project.
At the end, in your app module
or you own application module, edit
the build.gradle
file, add a line in your dependencies:
compile project(':library')
BTW, you can change the folder name ("library" in this case) to any
name you want (like "standout-library" if you want) when copy it into
you project's root folder, then, when you edit the gradle files, just
use the changed name.
但出现以下错误:
Error:Configuration with name 'default' not found.
我的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.mapandmap.standout"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':standout')
compile 'com.android.support:appcompat-v7:22.1.1'
}
我的settings.gradle:
include ':app',':standout'
我的项目树截图:
您需要在 "standout" 库的每个文件中解析 R,现在显示为红色。
您可以通过这样做简单地添加。转到 Android Studio File->Project Structure-> + ,您将获得四个用于添加新模块的选项。从那里选择 "Import Existing Project"->Next-> 浏览到您下载库的目录并选择 "library" 目录,然后选择 "Finish".Android Studio 将花费一些时间将库同步到您的项目。最后在设置中添加依赖。我刚刚通过将这个库添加到一个项目中进行了测试,并且它运行良好。
您可以将库移动到主 "app" 项目,但最好将其添加为依赖项。
我遵循了 sbr1308 的回答,但我还需要做一些事情 things.What 你必须做:
- 前往AndroidStudio File->Project Structure-> + ,你会得到四个添加新模块的选项。从那里选择 "Import Existing Project"->下一步-> 浏览到您下载库的目录并选择 "library" 目录,然后选择 "Finish"
- 如果库的 类 中有任何错误,则转到文件->无效 Caches/Restart->无效,Restart.It 需要时间来建立索引。
- 您必须在应用程序的
build.gradle
中添加依赖项
编译项目(':standOut')然后同步。
我正在尝试导入 standout library,这是一个 github 项目作为我的 project.What 中的库,我试过如下:
在我的根项目目录中创建了一个名为 'libs'
的文件夹- 已将 git 上 Standout 项目的完整文件夹 'library' 复制到 'libs'
- 重命名了我刚刚复制到的文件夹 'library',例如"standout"(只是为了避免混淆)
现在使用以下命令将此库添加到我的
settings.gradle
中:包括':libs:standout'
转到我的 AppProject 的
build.gradle
文件并将以下行添加到我的 'dependencies':编译项目(':libs:standout')
但是我得到了错误然后像这样添加
compile fileTree(dir: 'libs', include: ['standout'])
gradle同步成功但是库项目的src文件上有红色标记。
我无法从MainActivity访问库src文件我的 Project.As github 项目不是 android studio 项目,我需要为此做任何额外的事情吗?
我尝试了 Wesley 建议的以下方法:
Download or clone the git repository, copy the
library
folder into your project root folder.Then in your project
settings.gradle
file, add a':library'
at the end of the include line, like this:include ':app', ':library'
, thengradle sync
your whole project.At the end, in your
app module
or you own application module, edit thebuild.gradle
file, add a line in your dependencies:
compile project(':library')
BTW, you can change the folder name ("library" in this case) to any name you want (like "standout-library" if you want) when copy it into you project's root folder, then, when you edit the gradle files, just use the changed name.
但出现以下错误:
Error:Configuration with name 'default' not found.
我的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.mapandmap.standout"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':standout')
compile 'com.android.support:appcompat-v7:22.1.1'
}
我的settings.gradle:
include ':app',':standout'
我的项目树截图:
您需要在 "standout" 库的每个文件中解析 R,现在显示为红色。 您可以通过这样做简单地添加。转到 Android Studio File->Project Structure-> + ,您将获得四个用于添加新模块的选项。从那里选择 "Import Existing Project"->Next-> 浏览到您下载库的目录并选择 "library" 目录,然后选择 "Finish".Android Studio 将花费一些时间将库同步到您的项目。最后在设置中添加依赖。我刚刚通过将这个库添加到一个项目中进行了测试,并且它运行良好。 您可以将库移动到主 "app" 项目,但最好将其添加为依赖项。
我遵循了 sbr1308 的回答,但我还需要做一些事情 things.What 你必须做:
- 前往AndroidStudio File->Project Structure-> + ,你会得到四个添加新模块的选项。从那里选择 "Import Existing Project"->下一步-> 浏览到您下载库的目录并选择 "library" 目录,然后选择 "Finish"
- 如果库的 类 中有任何错误,则转到文件->无效 Caches/Restart->无效,Restart.It 需要时间来建立索引。
- 您必须在应用程序的
build.gradle
中添加依赖项 编译项目(':standOut')然后同步。