如何导入非Github上的Android Studio项目作为库添加到Android的工作室? [英] How to Import Github non Android Studio Project as library into Android Studio?
问题描述
我要导入出色库这是github上的项目作为我project.What库我下面尝试是:
I am trying to import standout library which is a github project as library in my project.What i tried is below:
-
创建了一个名为在我的项目根目录文件夹库
created a folder in my root project directory named 'libs'
- 复制混帐上的突出项目的整个文件夹'库'变成'库'
- 改名,我只是复制到文件夹图书馆如杰出(只是为了避免混淆)
-
现在添加了这个库在我的
settings.gradle
使用以下命令:
包括':库:突出
去我AppProject我的的build.gradle
文件并添加以下行到我的'依赖':
going to my build.gradle
file of my AppProject and added the following line to my 'dependencies':
编制项目(':库:突出')
compile project(':libs:standout')
但我得到的错误,然后加入这样的
but i got error and then added like this
compile fileTree(dir: 'libs', include: ['standout'])
同步的gradle成功,但没有对库项目的src文件红色标记。。结果我无法访问从MainActivity库SRC文件我Project.As GitHub的项目不是机器人工作室项目做我需要做任何额外是什么?
gradle sync was successful but there is red mark on the src files of the library project..
I couldn't access the library src files from MainActivity of my Project.As the github project wasn't the android studio project do i need to do anything extra for that?
我曾尝试通过以下建议韦斯利方式:
I have tried below way suggested by Wesley:
下载或克隆Git仓库,复制库
文件夹成
你的项目的根文件夹。
Download or clone the git repository, copy the
library
folder into your project root folder.
然后在你的项目中 settings.gradle
文件,添加一个':库
在
包括':应用程序中包含行,像这样的结尾,':库
,然后
同步的gradle
整个项目。
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.
最后,你的应用模块
或你自己的应用程序模块,编辑
在的build.gradle
文件,在你的依赖添加一行:
At the end, in your app module
or you own application module, edit
the build.gradle
file, add a line in your dependencies:
编制项目(':库')
顺便说一下,可以(在这种情况下,库)改变文件夹名称的任何
命名你想(如鹤立鸡群库如果你想),当它复制到
你项目的根文件夹,然后,当你在编辑的gradle文件,只
使用改名。
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'
我的项目树的截图:
推荐答案
我跟着sbr1308的答案,但我必须做一些更多的things.What你要做的:
I followed the answer of sbr1308 but I have to do some more things.What you have to do:
- 转至Android的工作室文件 - >项目结构 - > +,您将获得四个选项添加新的模块。从那里选择导入现有项目 - >下一步 - >浏览的目录,你已经下载库,然后选择库目录,然后选择完成
- 如果有一个在库中的类的任何错误,然后转到文件 - >无效缓存/重新开机>废止和Restart.It需要时间来建立索引。
- 您必须添加在依赖应用程序的
的build.gradle
编制项目(:突出'),然后同步
- Go to Android Studio File->Project Structure-> + , You will get four options to add a new module. From there choose "Import Existing Project"->Next-> browse to the directory you have downloaded library and choose "library" directory and then "Finish"
- If there is any error in the classes of the library then Go to File->Invalidate Caches/Restart->Invalidate and Restart.It will take time to indexing.
- You have to add the dependency in the app's
build.gradle
compile project(':standOut') and then sync.
这篇关于如何导入非Github上的Android Studio项目作为库添加到Android的工作室?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!