简体   繁体   English

如何从多个java类(单个包)正确创建/使用.aar或.jar文件,以便在android studio中的不同项目中使用它

[英]How to properly create/use .aar or .jar file from multple java classes ( single package) to use it in different projects in android studio

i tried many different approaches, to use my library in different projects but in each on of them i failed miserably. 我尝试了很多不同的方法,在不同的项目中使用我的库,但在每个项目中,我都失败了。

here is what i did for the last try, 这是我为最后一次尝试做的,

I created a module / android library 我创建了一个模块/ android库

and inside of them i created my Java Classes (3 to be exact) 在他们内部我创建了我的Java类(确切地说是3个)

this is my moduke's gradle 这是我的moduke的gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.google.android.gms:play-services:6.5.87'

}

and than i builded my application. 而且我建立了我的申请。

Desktop/SDK/myLib/build/outputs/aar

At this location i found out my myLib-debug.aar .aar 在这个位置,我找到了myLib-debug.aar .aar

i added that to my test project to see if could use my class methods, 我把它添加到我的测试项目中,看看是否可以使用我的类方法,

compile files('src/main/java/lib/myLib-debug.aar') 编译文件('src / main / java / lib / myLib-debug.aar')

i added this to my dependencie and gradle sync didnt return any error, 我将此添加到我的dependencie并且gradle sync没有返回任何错误,

and when i tried to import the package; 当我试图导入包裹时;

this is what i could import 这是我可以导入的

import com.myLib.android.*; import com.myLib.android。*;

and it seems fine since my module's package name is com.myLib.android 它似乎很好,因为我的模块的包名是com.myLib.android

but when i try to reach my class Methods, nothing shows up. 但是当我试图达到我的班级方法时,什么都没有出现。

What am i missing? 我错过了什么?

If you have another module in the same project and want to depend on it, add a direct module dependency. 如果您在同一个项目中有另一个模块并希望依赖它,请添加直接模块依赖项。 You can do this via File > Project Structure > Dependencies > + > Module Dependency. 您可以通过文件>项目结构>依赖关系> +>模块依赖关系来完成此操作。

Using this UI will add the following dependency to the module; 使用此UI将向模块添加以下依赖项; you don't have to make the modifications to the build script yourself, but this what the UI will do: 您不必自己对构建脚本进行修改,但这将是UI将执行的操作:

dependencies {
    ...
    compile project(':my_module')
}

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

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