简体   繁体   English

Android Studio第三方库集成

[英]Android Studio 3rd Party Library Integration

I've got to integrate a 3rd party library in to My Android Studio project and that works great without any issue. 我必须将第3方库集成到“我的Android Studio”项目中,并且效果很好,没有任何问题。

It asks to add following configuration to the project ' s build.gradle (sample configuration as follows) 它要求在项目 build.gradle中添加以下配置(示例配置如下)

allprojects {
    repositories {
        jcenter()
         maven {
            url "http://link/location"
         }
    }
}

And then to add dependencies to the app.gradle as follows 然后将依赖项添加到app.gradle中 ,如下所示

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.android.support:support-v4:24.1.1'
    compile 'com.android.support:cardview-v7:24.1.1'
    compile 'xxx.xx:xxx:1.11.0:@aar'
}

But my requirement here is to create a library module (with in the project) that wraps this 3rd party library integration with in that. 但是我在这里的要求是创建一个库模块(在项目中使用),在其中包装此第三方库集成。

Idea is to distrubute my library that contains few public methods (that use this 3rd party library methods in that) to others to integrate with in their apps. 想法是将包含很少的公共方法(在其中使用此第三方库方法)的我的库与他人共享,以集成到他们的应用程序中。

As I mentioned earlier to use this 3rd party library I need to use their own Maven Repository and asks to place setting in Projects build.gradle. 如前所述,要使用此第三方库,我需要使用自己的Maven存储库,并要求将设置放置在Projects build.gradle中。 But as I want to warp all within My Library Module I just tested adding repository bit in to Library Module's build.gradle. 但是,由于我想在“我的图书馆模块”中进行全部扭曲,因此我刚刚测试了将存储库位添加到图书馆模块的 build.gradle中。 But this provides compile errors. 但这提供了编译错误。

 repositories {
    jcenter()
     maven {
        url "http://link/location"
     }
 } 

My Question is can I achieve what I am trying to do? 我的问题是我能实现我的目标吗? If so what I am missing here. 如果是这样,我在这里想念的是什么。 Thanks 谢谢

EDITS 编辑

Briefly what I am trying to do. 简而言之,我正在尝试做的事情。

This 3rd party library is not available in standard jcenter or mavenCentral repositories. 该第3方库在标准jcenter或mavenCentral存储库中不可用。 Instead it resides on their own Maven Repository Server. 相反,它位于自己的Maven存储库服务器上。 That's why when need to integrate it asks to specify server location in root level (project) build.gradle as follows. 这就是为什么当需要集成时,它要求在根级别(项目)build.gradle中指定服务器位置,如下所示。 Then I can add dependencies... 然后我可以添加依赖项...

allprojects {
    repositories {
        jcenter()
         maven {
            url "http://link/location"
         }
    }
}

But as I want to wrap up this integration within Library Module tried to add above repository location in to gradle.build with in My Library Module. 但是,由于我想在库模块中集成此集成,因此尝试在My Library Module中将上述存储库位置添加到gradle.build中。

So I can Access those classes but Main Application that compile MY Library project saying can't resolve libraries in 3rd party Library location. 因此,我可以访问那些类,但是编译MY Library项目的Main Application说无法解析第三方Library位置中的库。 Actually Main Application should NOT want to know as long as My Library Module knows it... 实际上,只要我的图书馆模块知道它,主应用程序就不想知道...

Actually Main Application should NOT want to know as long as My Library Module knows it 实际上,只要我的图书馆模块知道它,主应用程序就不想知道

If the third-party module is open source, fork it, put your wrapper code in the fork, and ship the fork by your own means. 如果第三方模块是开源的,请对其进行分叉,将包装代码放入分叉中,然后以自己的方式发货。

If the third-party module is not open source, discuss with the vendor what your options are for distributing this code by some other means (eg, your own internal repository, alongside your own library). 如果第三方模块不是开源的,请与供应商讨论通过其他方式(例如,您自己的内部存储库以及自己的库)分发此代码的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM