Android的依赖摇篮 [英] Android Gradle Dependency

查看:152
本文介绍了Android的依赖摇篮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用本地AAR文件为我们的项目之一,低于查询。
我有2个库和1个应用程序。

2库是:
1. TestLib2
2. TestLib1

1的应用程序:
1.测试

我用TestLib2创建了一个AAR文件,并在使用TestLib1参考flatDir它。我可以访问TestLib2功能present没有任何问题。

现在我用TestLib1创建了一个AAR文件,并在测试使用flatDir参考它。我可以在TestLib1只能访问功能present。为了访问TestLib2我必须将它添加到测试应用程序为一体的多库。

因此​​,依赖是象下面这样:

 测试
| _ TestLib1
   | _ TestLib2

在AAR文件的情况是上述可能的?

此外,在为TestLib1 settings.gradle文件我提到,包括

 包括':应用',':testlib2调试

在哪里应用指的是TestLib1

该文件的build.gradle并没有真正有味道如此,我甚至不有利用他们作为,因为只包含了Java件code其罐子的任何限制。

在相同的任何帮助是非常AP preciated。

BR,
Jayshil

更新1:
下面我试着以及在TestLib1和测试的build.gradle。
仍然没有运气。

  {相关性
    编译(名称:testlib2调试,分机:'AAR'){
        传递= TRUE;
    }
}

和用于测试应用程序

 编译(名称:testlib1调试,分机:'AAR'){
        传递= TRUE;
}


解决方案

所以,我终于想通了一个解决方案。
它适用于上述的2级依赖性。

有关测试库2创建一个JAR文件。

 任务clearJar(类型:删除){
    删除构建/输出/ loggingSDK.jar
}任务makeJar(类型:复制){
    从('构建/中间体/包/发行/')
    成('构建/输出/')
    包括:('classes.jar'的)
    重命名('classes.jar'的,'testlib2.jar')
}makeJar.dependsOn(clearJar,编译)

通过使用命令

  gradle这个makeJar

您会得到一个testlib2.jar

复制到您的TestLib1此

使用命令

 组装的gradle

这会造成调试和发布版本

以调试版本,并将其复制在测试你就可以调用TestLib1的功能,这反过来又调用TestLib2功能

希望这可以帮助别人寻找这样的解决方案

I am using local aar files for one of our projects and have below Query. I have 2 libraries and 1 application.

2 libraries are: 1. TestLib2 2. TestLib1

1 Application is: 1. Test

I use a aar file created for TestLib2 and refer it using flatDir in TestLib1. I can access the functions present in TestLib2 without any problems.

Now I use a aar file created for TestLib1 and refer it using flatDir in Test. I can access only the functions present in TestLib1. For accessing TestLib2 i have to add it to Test application as one more Library.

So the dependency is like below:

Test
|_ TestLib1
   |_ TestLib2

Is the above possible in case of aar files?

Also in settings.gradle file for TestLib1 i mention to include

include ':app', ':testlib2-debug'

Where app refers to the TestLib1

The build.gradle file doesnt really have any flavors as such and i dont even have any restriction of using them as jar's since its containing only the java piece of code.

Any help on the same is much appreciated.

BR, Jayshil

Update 1: I tried below as well in build.gradle of TestLib1 and Test. Still no luck.

dependencies {
    compile (name:'testlib2-debug', ext:'aar') {
        transitive = true;
    }
}

And for Test App

compile (name:'testlib1-debug', ext:'aar')  {
        transitive = true;
}

解决方案

So i finally figured out a solution for this. It works for 2 level dependency mentioned above.

Create a jar file for Test Lib 2.

task clearJar(type: Delete) {
    delete 'build/outputs/loggingSDK.jar'
}

task makeJar(type: Copy) {
    from('build/intermediates/bundles/release/')
    into('build/outputs/')
    include('classes.jar')
    rename ('classes.jar', 'testlib2.jar')
}

makeJar.dependsOn(clearJar, build)

By using a the command

gradle makeJar

You would have got a testlib2.jar

Copy this into your TestLib1

Use command

gradle assemble

This would create debug and release version

Take the debug version and copy it in Test you would be able to call functions of TestLib1 which in turn calls function of TestLib2

Hope this may help someone looking for such solution

这篇关于Android的依赖摇篮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆