简体   繁体   English

如何通过其AAR文件重用已实现的依赖项

[英]How to reuse implemented dependency with its aar files

i have some project with some dependency in my first computer(C1) and i have a computer(C2) that has some problem with internet(its isolated).i want to reuse my downloded libs from my C1 and put it in C2. 我在我的第一台计算机(C1)中有一些项目具有一定的依赖性,并且我的计算机(C2)在Internet(隔离)方面存在一些问题。我想重用从C1下载的库并将其放到C2中。 i don't want to use .jar file. 我不想使用.jar文件。 just aar files. 只是aar文件。

You can copy the gradle cache 您可以复制gradle缓存

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): 将归档文件转移到脱机计算机上,解压缩并使用flatDir存储库(如果您希望在脱机时使用它而不每次都添加它,则可能有条件):

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

then run on C2 with --offline parameter for gradle 然后在C2上使用--offline参数运行gradle

You can use either the Zip , Tar or Jar tasks to export the dependencies, depending on your liking. 您可以根据自己的喜好使用ZipTarJar任务导出依赖项。 See creating archives 请参阅创建档案

Also just plain copying of the .gradle directory to the same location (because of absolute paths) from C1 to C2 should work. 同样,从C1到C2仅将.gradle目录普通复制到同一位置(由于绝对路径)也应该起作用。

thanks to everybody. 感谢大家。 the solution is: 1. add dependency to your online computer.(gradle will build and cache .aar file in the ".gradle\\caches\\modules-2\\files-2.1\\${YOUR.PACKAGE.NAME}\\${YOUR LIB NAME}\\${YOUR_LIB_VERSION}{HASH_FOLDER}\\"). 解决方案是:1.向您的在线计算机添加依赖项。(gradle将在.gradle \\ caches \\ modules-2 \\ files-2.1 \\ $ {YOUR.PACKAGE.NAME} \\ $ {YOUR中生成并缓存.aar文件。 LIB NAME} \\ $ {YOUR_LIB_VERSION} {HASH_FOLDER} \\“)。

If you don't know your package name just take a look at build.gradle(app level). 如果您不知道软件包名称,请查看build.gradle(应用程序级别)。 In the dependency block you can find it like: Implemented 'your.package.name:your lib name:your_lib_version' 在依赖关系块中,您可以找到它,类似于:实现“ your.package.name:您的lib名称:your_lib_version”

2.copy the .aar file. 2.复制.aar文件。

3.in the offline computer open android studio then in the project view(top left corner) change android to project. 3.在离线计算机中打开android studio,然后在项目视图(左上角)中将android更改为project。 then go to app folder and you can see " libs " folder. 然后转到应用程序文件夹,您可以看到“ libs ”文件夹。

4.drag and drop the .aar file to libs and click "ok i want modify this file anyway" 4.将.aar文件拖放到libs中,然后单击“确定,我仍然想修改此文件”

5.then go to build.gradle(app level) and paste this code there : 5.然后转到build.gradle(应用程序级别)并将此代码粘贴到此处:

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

6.put this line in the dependency block in the build.gradle(app level) 6.将此行放入build.gradle(应用程序级别)的依赖项块中

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

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

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