java 如何手动向 Android Studio 添加依赖项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37721844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add dependency to Android Studio manually
提问by afzali
I try several times to add dependency to my project and each time give error
the dependency that I want to add them are 'de.hdodenhof:circleimageview:1.3.0'
and 'com.github.bumptech.glide:glide:3.6.1'
so I want to download these and add to my project manually is it possible and if Yes How?
我尝试了几次向我的项目添加依赖项,每次都给出错误,我想添加它们的依赖项是 'de.hdodenhof:circleimageview:1.3.0'
,'com.github.bumptech.glide:glide:3.6.1'
所以我想下载这些并手动添加到我的项目中是否有可能,如果是,如何?
Here is my application's build.gradle
这是我的应用程序 build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '24.0.0 rc4'
defaultConfig {
applicationId "ir.esfandune.material"
minSdkVersion 23
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'classes.dex'
}
}
repositories {
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
compile 'com.android.support:design:23.0.0'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:cardview-v7:23.0.0'
compile 'com.android.support:recyclerview-v7:23.0.0'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.github.rey5137:material:1.2.1.6-SNAPSHOT'
compile project(':material-dialogs')
compile files('lib/de.hdodenhof/circleimageview/1.3.0/jars/classes.jar')
//*** added from orginal source
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.github.bumptech.glide:glide:3.6.1'
}
回答by afzali
download the jar/aar file of your library you want
下载你想要的库的 jar/aar 文件
copy files into libs directory in your app folder for *.jar files: add this code to dependency on your gradle file
将文件复制到您的 app 文件夹中的 libs 目录中以获取 *.jar 文件:将此代码添加到您的 gradle 文件的依赖项中
compile files('libs/library.jar')
for *.aar files: try from projectstructure / new module/ import from aar/jar
对于 *.aar 文件:尝试从项目结构/新模块/从 aar/jar 导入
good luck
祝你好运
回答by takmilul
in your project panel expand the GradleScripts tab. you will see 2 build.gradle file there. open the second one build.gradle(module:app) file. in the end of the file you will see a section like:
在您的项目面板中展开 GradleScripts 选项卡。你会在那里看到 2 个 build.gradle 文件。打开第二个 build.gradle(module:app) 文件。在文件的末尾,您将看到如下所示的部分:
dependencies {
compile 'com.android.support:appcompat-v7:23.0.0'
}
add a new dependency here like this:
在此处添加一个新的依赖项,如下所示:
dependencies {
compile 'com.android.support:appcompat-v7:23.0.0'
//manually added dependency
compile 'com.android.support:design:23.0.0'
}
回答by Phillen
just copy this in dependencies
只需将其复制到依赖项中
compile 'de.hdodenhof:circleimageview:1.3.0'
and press 'sync project with gradle files' button
然后按“同步项目与 gradle 文件”按钮
Then use it wherever you want by pasting the code below
然后通过粘贴下面的代码在任何你想要的地方使用它
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/profile"
app:civ_border_width="2dp"
app:civ_border_color="#FF000000"/>
回答by Akeshwar Jha
I had a similar problem and as @SaravInfern pointed out in the comments, I solved it by importing the project as a module.
我有一个类似的问题,正如@SaravInfern 在评论中指出的那样,我通过将项目作为模块导入来解决它。
- Clone the project.
- File -> New -> Import module, and follow the steps.
- Let the gradle do all the necessary dependencies download once you import that module.
- Open the gradle file of this new module and add
apply plugin: 'com.android.library'
to it (earlier, it might becom.android.library
) - In the dependencies block, add this:
compile project(":app")
where,app
is name of the imported module.
- 克隆项目。
- 文件 -> 新建 -> 导入模块,然后按照步骤操作。
- 导入该模块后,让 gradle 完成所有必要的依赖项下载。
- 打开这个新模块的 gradle 文件并添加
apply plugin: 'com.android.library'
到其中(之前可能是com.android.library
) - 在依赖项块中,添加以下内容:
compile project(":app")
其中,app
是导入模块的名称。
Build the project then. It should build successfully. You can refer to this blogand this SO threadfor more elaborate solution.
回答by Ambilpura Sunil Kumar
Yes you can manually update the dependencies in build.gradle system
Just copy any of the existing dependency and rename with yours required dependency..
Example:
dependencies {
compile 'com.android.support:design:23.0.0'// this is default dependency
compile 'de.hdodenhof:circleimageview:1.3.0' // this is your dependency..
}
Issues your get..
1. android machine warn you to use implements instand of complie..(its a warning ignore it)
2. de.hdodenhof:circleimageview:1.3.0 change of version...(use latest if your using latest then change to lower version).
.@Sunil, Try this It will work....