英文:
Add gradle dependencies(build.gradle) in .aar file Android
问题
我有一个使用第三方库的Android库项目。我已经创建了它的 .aar 文件,并将该 .aar 文件导入到另一个项目中。类和资源已经导入,但是 Gradle 库没有被导入。我不想在项目中再次提及这些依赖关系。
有没有办法通过 .aar 文件或其他包含 build.gradle 或依赖项的方式来导入那个项目呢?
英文:
I am having an android library project which is using third party libraries. I have created it's .aar file and imported the .aar file in a different project. Classes and resources are imported but the gradle libraries are not imported. I don't want to mention those dependencies again in the project.
Is there any way to import that project with .aar file or something else which include build.gradle or dependencies.
答案1
得分: 0
如果您在dependencies
块中包含此库,则尝试使用api
替代implementation
。
英文:
If you are including this library in dependencies
block then try to use api
instead of implementation
.
答案2
得分: 0
AAR文件不包含在app/build.gradle
中提到的外部依赖项,所以我们不会直接添加它,而是将其上传到本地Maven并进行集成。
要在本地Maven中上传它,您可以在app/build.gradle
中添加以下函数:
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://localhost" + System.getenv("HOME") + "/.m2/repository")
pom.version = '1.0-SNAPSHOT'
pom.groupId = 'your.package'
pom.artifactId = 'sdk-name'
}
}
}
您可以根据您的需求更改pom版本、groupId和artifactId。
如果此过程已完成,您可以集成该库。
-
在要添加库的项目的
app/build.gradle
中指定路径。implementation 'your.package:sdk-name:1.0-SNAPSHOT'
-
在
project/build.gradle
中添加以下内容allprojects{ ... mavenLocal() }
这将在本地机器中搜索库。
如果仍然遇到错误,请尝试清除缓存并从“文件”菜单中重新启动Android Studio。
英文:
AAR file does not include external dependencies which are mention in app/build.gradle
so instead of adding it directly we upload to local maven and integrate it.
To upload it in your local maven you can add the following function in app/build.gradle
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://localhost" + System.getenv("HOME") + "/.m2/repository")
pom.version = '1.0-SNAPSHOT'
pom.groupId = 'your.package'
pom.artifactId = 'sdk-name'
}
}
}
You can change the pom version, groupId and artifactId according to how you want to use it.
If this process is completed you can integrate the library.
-
In the
app/build.gradle
of the project in which you want to add the
library specify the path.implementation 'your.package:sdk-name:1.0-SNAPSHOT'
-
In the
project/build.gradle
add the followingallprojects{ ... mavenLocal() }
This will search for the library in the local machine.
If still, you get some error try to invalidate caches and restart the android-studio from the File Menu.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论