有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使用aar文件重用实现的依赖关系

我的第一台计算机(C1)中有一些依赖性的项目,我的一台计算机(C2)在互联网上有一些问题(它是孤立的)。我想重用C1中的向下隐藏的LIB,并将其放入C2中。我不想用。jar文件。只是aar文件


共 (2) 个答案

  1. # 1 楼答案

    你可以copy the gradle cache

    One way you could do this is to gather all of your dependencies in an archive. For example, something like this should grab everything in all configurations:

    task bundleDependencies(type: Zip) {
         baseName = 'dependencies'
         configurations.each { configuration ->
             if (configuration.canBeResolved) { from configuration }
         } 
         destinationDir = file('your/Path') // set path
      }
    

    Transfer the archive to the offline machine, extract, and use a flatDir repository (maybe conditionally if you want to use it when offline without adding it each time):

    repositories {
         if (gradle.startParamter.offline) {
             flatDir { dirs 'path/to/extracted/dependencies/zip' }
         } 
    }
    

    然后使用gradle的 offline参数在C2上运行

    您可以使用ZipTarJar任务导出依赖项,具体取决于您的喜好。见creating archives

    也只是简单的复制。从C1到C2的同一位置的渐变目录(因为绝对路径)应该可以工作

  2. # 2 楼答案

    谢谢大家。解决办法是: 1.向联机计算机添加依赖项。(gradle将在“.gradle\caches\modules-2\files-2.1\${YOUR.PACKAGE.NAME}\${YOUR LIB NAME}\${YOUR_LIB_VERSION}{HASH_FOLDER}\”)中生成并缓存.aar文件

    If you don’t know your package name just take a look at build.gradle(app level). In the dependency block you can find it like: Implemented ‘your.package.name:your lib name:your_lib_version’

    二,。抄袭。aar文件

    三,。在脱机计算机中打开android studio,然后在项目视图(左上角)中将android更改为project。然后转到应用程序文件夹,您可以看到“libs”文件夹

    四,。拖放。aar文件到libs并单击“确定我仍要修改此文件”

    五,。然后去建造。gradle(应用程序级别)并将此代码粘贴到:

    allprojects {
      repositories {
       jcenter()
       flatDir {
        dirs 'libs'
       }
      }
    }
    

    六,。将此行放在生成中的依赖项块中。gradle(应用程序级)

    dependencies {
     compile(name:'your lib name', ext:'aar')
    }