简体   繁体   English

Android-如何将模块转换为jar

[英]Android-How to convert module to jar

I have imported library module in my project. 我已经在项目中导入了库模块。 but I want to convert existing library module to a jar and then I want to use this jar(library module) in my current project.but I did this all process and trying to a specific class in my layout but The following classes could not be found: - com.halilibo.bettervideoplayer.BetterVideoPlayer, this error getting. 但是我想将现有的库模块转换为jar,然后在当前项目中使用此jar(库模块)。但是我完成了所有过程,并尝试在布局中使用特定的类,但以下类不能找到:-com.halilibo.bettervideoplayer.BetterVideoPlayer,此错误得到。 The main issue is that jar file only contain java classes but module also contains resources, drawable also. 主要问题是jar文件仅包含java类,而module也包含可绘制的资源。 I converted my module to jar but specific class is not getting imported. 我将模块转换为jar,但未导入特定类。

You need to create AAR file instead of JAR as you have to include resources. 您需要创建AAR文件而不是JAR文件,因为您必须包含资源。

Library reuse has long been available in Java based applications through Java Archive (.jar) files. 长期以来,通过Java存档(.jar)文件在基于Java的应用程序中都可以重用库。 Android AAR files build upon this concept to allow you to package not only the source code but also the libraries self contained Android resources. Android AAR文件基于此概念构建,可让您不仅打包源代码,而且打包自包含的Android资源。 The library can have its own manifest and resources and can also optionally provide assets, NDK built libraries, proguard configuration and even its own custom lint filters. 该库可以具有其自己的清单和资源,还可以选择提供资产,NDK构建的库,proguard配置,甚至其自己的自定义棉绒过滤器。 This is all bundled into a zip archive that can be published to a repository for your team (or the world!) to get easy access from a Gradle build. 所有这些都捆绑在一个zip归档文件中,该归档文件可以发布到您的团队(或全世界!)的存储库中,以便从Gradle构建中轻松访问。

  1. Start by selecting New Module… from the File menu 首先从“文件”菜单中选择“新模块”。
  2. Select Android Library as the module to be created 选择“ Android库”作为要创建的模块
  3. Step through the process of using a template for the creation of your library much like creating a new project 逐步完成使用模板来创建库的过程,就像创建一个新项目一样

One key difference in the created library and an Android application will be the libraries Gradle build script includes apply plugin: com.android.library instead of apply plugin: com.android.application . 创建的库和Android应用程序之间的一个主要区别是Gradle构建脚本库包含com.android.library插件: com.android.library而不是com.android.application插件: com.android.application

When you build your project the AAR file will automatically be assembled and placed in these folders 当您构建项目时,AAR文件将自动组装并放置在这些文件夹中

| build
| outputs
      | aar
           | applib-debug.aar
           | applib-release.aar

https://androidbycode.wordpress.com/2015/02/23/building-an-aar-library-in-android-studio/ https://androidbycode.wordpress.com/2015/02/23/building-an-aar-library-in-android-studio/

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

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