I know of Android Library projects, which allow you to create a shared-source project that can be pulled into Android Applications as needed. However, that requires that source be available.
我知道Android程序库项目,它允许您创建一个共享源项目,可以根据需要将其拉入Android应用程序。但是,这要求该源代码是可用的。
I'm looking for a way to build and distribute a closed-source library that can be used in other Android projects like a traditional JAR. This will require usage of the Android compiler, so it's not a vanilla-Java JAR file. FWIW, I do not need to embed resources/layouts in the JAR.
我正在寻找一种方法来构建和发布一个封闭源代码库,可以用于其他Android项目,比如传统的JAR。这需要使用Android编译器,所以它不是vanilla-Java JAR文件。FWIW,我不需要在JAR中嵌入资源/布局。
I've seen http://andparcel.com/ but it feels like a workaround, and I would rather use something 'officially supported' by Google. Also, I need to make sure that the JAR I build is compatible with old/new version of the Android SDK (i.e. I need a way to set the target platform version, etc).
我看过http://andparcel.com/,但感觉像是一个解决方案,我宁愿使用谷歌提供的“官方支持”。另外,我需要确保我构建的JAR与Android SDK的旧/新版本兼容(例如,我需要一种设置目标平台版本的方法,等等)。
Do the latest Android toolsets allow for the creation/consumption of JAR binaries? Can you point to some documentation on how I can do it?
最新的Android工具集允许创建/使用JAR二进制文件吗?你能指出一些关于我如何做这件事的文件吗?
48
If you create a Android Library project without having any resources, the ADT (first noticed in r16) will create a .jar with the same name as the project in the 'bin' folder.
如果您在没有任何资源的情况下创建一个Android库项目,ADT(第一次在r16中注意到)将创建一个.jar,其名称与“bin”文件夹中的项目相同。
23
Android doesn't provide a special kind of Android-JAR. But what you can do is adding a build.xml to your project and build the JAR with ant.
Android并没有提供一种特殊的Android- jar。但是您可以做的是添加一个构建。xml到您的项目,并使用ant构建JAR。
My build.xml looks like this:
我的建立。xml是这样的:
This is my Android lib
Build the JAR by running ant jar
in your projects main folder.
通过在项目主文件夹中运行ant JAR来构建JAR。
17
You can create a "regular" Java project and import from there Android.jar. Then, you will have access to every component in the SDK. Then, you can export your project as jar... and load it from your Android app. This works great and it seems a preety straightforward way to do it.
您可以创建一个“常规”Java项目并从其中导入Android.jar。然后,您将能够访问SDK中的每个组件。然后,您可以将项目导出为jar…从你的安卓应用程序下载,这很好用,而且看起来很简单。
15
just go to properties of the project of which you want to make jar.Click on Android tab. and tick in the Is library. now you can see .jar file in the bin folder.use it where you want to use.
转到要创建jar的项目的属性。单击Android选项卡。在Is图书馆里打勾。现在您可以在bin文件夹中看到.jar文件。在你想使用的地方使用它。
10
The only solution 'officially supported' by Google is the Library project, and it requires the source code to be distributed. You can create a JAR in the normal way, but you cannot include or reference resources within it.
谷歌“正式支持”的唯一解决方案是Library项目,它需要分发源代码。您可以以常规方式创建JAR,但不能在其中包含或引用资源。
Unfortunately I think it is also not possible to include a packaged JAR within a Library project, as a means to get around the source code requirement.
不幸的是,我认为在库项目中包含打包的JAR也是不可能的,这是一种绕过源代码需求的方法。
8
In the latest build of Android Studio 1.2, the creation of JAR library has been made as simple as point and click.
在最新的Android Studio 1.2版本中,JAR库的创建非常简单,只需点一下。
Steps to follow :
步骤:
The next step is adding your Jar Library as dependency in your app. Simple as that just
下一步是将Jar库添加到应用程序中的依赖项中。
....Or you could just add the below line to your App gradle file
....或者你可以把下面的行添加到你的应用程序渐变文件中
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) // Default Gradle Task, should be already present
compile 'com.android.support:appcompat-v7:21.0.3' // Default Gradle Task, should be already present
compile project(':nameOfYourJarLibraryModule') // This is your jar library module
}
Google is promoting the Android Archive(AAR), even though JAR supported is brought back to android studio.To find out the difference between AAR and JAR refer this link
谷歌正在推广Android Archive(AAR),尽管JAR支持被带回了Android studio。要找出AAR和JAR之间的区别,请参考这个链接。
6
Try this: This works
试试这个:这个作品
1) make your library project a normal project by deselecting IsLibrary flag.
1)取消IsLibrary标志,使您的library project成为一个正常的项目。
2) Execute your project as Android Application. (It will not show any error)
2)以Android应用程序执行项目。(不会显示任何错误)
3) you'll find a .jar file in bin folder along with .apk.
3)您将在bin文件夹中找到一个.jar文件和.apk文件。
4) Give you .jar who want to use your library.
4)给你.jar,谁想用你的库。
5) Tell them to just import external jar into build path.
5)告诉他们将外部jar导入到构建路径中。
this will works fine with all the resources. best of luck.
这对所有资源都很有效。最好的运气。
1
The ADT creates a bin folder which contains all of the class files for all matching source file and directories in your project, you could using the jar command,create a jar archive containing these class files and directories and presumable your library, but of course the class files platform level would only be targeted for current level of the project build- you would need a different jar file for each platform level; However the great thing about this is that the R.class file is include in the project directory tree and therefor you have access to its resources. I don't know if this is the official way to do things in android, but it worked for me.
ADT创建一个bin文件夹中包含的所有类文件所有匹配的源文件和目录在你的项目中,你可以使用jar命令,创建一个包含这些类的jar归档文件和目录,可能有的你的图书馆,当然类文件平台水平只会针对目前的项目构建——你需要一个不同的jar文件为每个平台水平;但是最棒的是R。类文件包含在项目目录树中,因此您可以访问它的资源。我不知道这是否是android的官方操作方式,但它对我起了作用。
0
In our project, we are creating apk (using apkbuilder) which is installed in /system/framework and added this apk in default classpath. For compilation of applications using the jar, we are creating a jar file (using jar c).
在我们的项目中,我们正在创建安装在/system/framework中的apk(使用apkbuilder),并在默认的类路径中添加这个apk。对于使用jar的应用程序的编译,我们正在创建一个jar文件(使用jar c)。
Note: We don't have any resources in the library.
注意:我们在库中没有任何资源。
0
.jar is just a .zip file which contains .class file (you can try change extension of any .jar file to .zip then see the result). Easily, you can create any .jar library for any purpose by zipping .class file.
jar只是一个.zip文件,其中包含.class文件(您可以尝试将任何.jar文件的扩展名更改为.zip,然后查看结果)。很容易,您可以通过zipping .class文件创建任何。jar库。
0
Open file project.properties enter value android.library=true
打开文件的项目。android.library = true属性输入值
save file, from eclipse menu for project, select 'build automatically' then select 'clean' brand new jar is created under bin
保存文件,从eclipse项目菜单中,选择“自动构建”,然后选择“清洁”,在bin下创建新的jar