热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

为发行版创建一个AndroidJar库-CreateanAndroidJarlibraryfordistribution

IknowofAndroidLibraryprojects,whichallowyoutocreateashared-sourceprojectthatcanbepu

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二进制文件吗?你能指出一些关于我如何做这件事的文件吗?

11 个解决方案

#1


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”文件夹中的项目相同。

#2


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。

#3


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…从你的安卓应用程序下载,这很好用,而且看起来很简单。

#4


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文件。在你想使用的地方使用它。

#5


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也是不可能的,这是一种绕过源代码需求的方法。

#6


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 :

步骤:

  • Goto File -> New -> New Module enter image description here
  • Goto文件->新->新模块
  • Select "Java Library" at the end of the options list enter image description here
  • 在选项列表的末尾选择“Java库”
  • Enter the name of the jar lib and name of class in it and hit finish button enter image description here
  • 输入jar库的名称和类的名称,然后单击finish按钮
  • Thats it !
  • 这就是它!

The next step is adding your Jar Library as dependency in your app. Simple as that just

下一步是将Jar库添加到应用程序中的依赖项中。

  • Goto File -> Project Structure -> Select 'app' -> Select 'Dependency'
  • Goto文件->项目结构->选择‘app’->选择‘Dependency’
  • Select the '+' at the bottom -> Select 'Module Dependency' enter image description here
  • 在底部选择“+”——>选择“模块依赖”
  • Select your jar lib module you just created above enter image description here enter image description here
  • 选择您刚刚创建的jar lib模块
  • Select Ok and thats it!
  • 选择Ok,这就是它!

....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之间的区别,请参考这个链接。

#7


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.

这对所有资源都很有效。最好的运气。

#8


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的官方操作方式,但它对我起了作用。

#9


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.

注意:我们在库中没有任何资源。

#10


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库。

#11


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


推荐阅读
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • 开发笔记:spring boot项目打成war包部署到服务器的步骤与注意事项
    本文介绍了将spring boot项目打成war包并部署到服务器的步骤与注意事项。通过本文的学习,读者可以了解到如何将spring boot项目打包成war包,并成功地部署到服务器上。 ... [详细]
  • 本文讨论了在shiro java配置中加入Shiro listener后启动失败的问题。作者引入了一系列jar包,并在web.xml中配置了相关内容,但启动后却无法正常运行。文章提供了具体引入的jar包和web.xml的配置内容,并指出可能的错误原因。该问题可能与jar包版本不兼容、web.xml配置错误等有关。 ... [详细]
  • Spring框架《一》简介
    Spring框架《一》1.Spring概述1.1简介1.2Spring模板二、IOC容器和Bean1.IOC和DI简介2.三种通过类型获取bean3.给bean的属性赋值3.1依赖 ... [详细]
  • Linux服务器密码过期策略、登录次数限制、私钥登录等配置方法
    本文介绍了在Linux服务器上进行密码过期策略、登录次数限制、私钥登录等配置的方法。通过修改配置文件中的参数,可以设置密码的有效期、最小间隔时间、最小长度,并在密码过期前进行提示。同时还介绍了如何进行公钥登录和修改默认账户用户名的操作。详细步骤和注意事项可参考本文内容。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • 本文介绍了如何清除Eclipse中SVN用户的设置。首先需要查看使用的SVN接口,然后根据接口类型找到相应的目录并删除相关文件。最后使用SVN更新或提交来应用更改。 ... [详细]
  • 本文介绍了Swing组件的用法,重点讲解了图标接口的定义和创建方法。图标接口用来将图标与各种组件相关联,可以是简单的绘画或使用磁盘上的GIF格式图像。文章详细介绍了图标接口的属性和绘制方法,并给出了一个菱形图标的实现示例。该示例可以配置图标的尺寸、颜色和填充状态。 ... [详细]
  • 如何实现JDK版本的切换功能,解决开发环境冲突问题
    本文介绍了在开发过程中遇到JDK版本冲突的情况,以及如何通过修改环境变量实现JDK版本的切换功能,解决开发环境冲突的问题。通过合理的切换环境,可以更好地进行项目开发。同时,提醒读者注意不仅限于1.7和1.8版本的转换,还要适应不同项目和个人开发习惯的需求。 ... [详细]
  • OpenMap教程4 – 图层概述
    本文介绍了OpenMap教程4中关于地图图层的内容,包括将ShapeLayer添加到MapBean中的方法,OpenMap支持的图层类型以及使用BufferedLayer创建图像的MapBean。此外,还介绍了Layer背景标志的作用和OMGraphicHandlerLayer的基础层类。 ... [详细]
author-avatar
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有