将gradle依赖项(build.gradle)添加到Android的.aar文件中。

huangapple go评论86阅读模式
英文:

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 following

    allprojects{
        ...
        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.

huangapple
  • 本文由 发表于 2020年9月21日 16:18:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/63988537.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定