Android Studio 3.0 version produces Jar packages or obfuscated Jar packages

The commands for producing jar packages are different for each version of Android Studio, so here are two methods for producing packages in Android Studio 3.0:

Method 1 (simple): Output the entire project as a jar package

1. First find the build.gradle file under the module project where the jar package needs to be generated, and add the task task directly at the bottom:

//AS 3.0 编译出build/intermediates/bundles/release/下的classes.jar包,并且完成出jar包
//dependsOn 就是代替手动去点击右侧gradle/对应module/other/transformClassesAndResourcesWithSyncLibJarsForRelease命令
task makeJar(type: Copy, dependsOn: ['transformClassesAndResourcesWithSyncLibJarsForRelease']) {
    from('build/intermediates/bundles/release/')//classes.jar 文件位置(AS版本不同位置不同)
    into('build/libs/jar/')//新jar包保存的位置,可根据自己需求修改
    
    exclude('**/BuildConfig.class') //exclude 命令就是新jar包需要删除的类或文件
    exclude('**/BuildConfig\$*.class')
    exclude('**/R.class')
    exclude('**/R\$*.class')
    include('**/*.class')
    include('proguard-rules.pro')//需要混淆就添加这行,不需要混淆此处可注销或删除
    include('classes.jar')//include 命令就是执行任务
    rename('classes.jar', 'test.jar') //修改新jar包的名称
}

   Note: If you use the classes.jar in the from('build/intermediates/bundles/debug/') directory above, you need to modify it to dependsOn: ['transformClassesAndResourcesWithSyncLibJarsForDebug']. In addition, please note that in the AS3.0 version, use dependsOn: [' compileReleaseJavaWithJavac'] is invalid. A jar package may appear, but there are no related resources or classes in the jar package.

2. Click the Terminal at the bottom of AS, use the command line to execute the task, and enter gradlew makeJar on the command line. In this way, all tasks including makeJar in the entire project will be executed, and all jar packages will be generated at once.

You can see that the execution is successful as shown below.

3. Finally, just find your new jar package directly in the directory corresponding to the into('build/libs/jar/') you set above:

4. Be sure to open the test.jar package to check whether the resource class is complete.

If it was helpful to you, please give it a like and leave?

 

 

Method 2 (Cumbersome): Create a jar package from a single module

1. First find the build.gradle file under the module project where the jar package needs to be generated, and add the task task directly at the bottom:

task makeJar(type: Copy) {
    from('build/intermediates/bundles/release/')//classes.jar 文件位置(AS版本不同位置不同)
    into('build/libs/jar/') //新jar包保存的位置,可根据自己需求修改

    exclude('**/BuildConfig.class')//exclude 命令就是 新jar包需要删除的类或文件
    exclude('**/BuildConfig\$*.class')
    exclude('**/R.class')
    exclude('**/R\$*.class')
    include('**/*.class')
    include('classes.jar')//include 命令就是执行任务
    rename('classes.jar', 'test.jar')//修改新jar包的名称
}

2. Click the Gradle button on the far right side of AS, find the corresponding module/other/transformClassesAndResourcesWithSyncLibJarsForRelease or transformClassesAndResourcesWithSyncLibJarsForDebug button below, and compile the classes.jar package in the build/intermediates/bundles/release/ directory:

3. Click the Terminal at the bottom of AS, use the command line to execute the task, and enter gradlew makeJar on the command line, so that the module that needs to generate the jar package will successfully generate the jar package.

You can see that the execution is successful as shown below.

3. Finally, just find your new jar package directly in the directory corresponding to the into('build/libs/jar/') you set above:

4. Be sure to open the test.jar package to check whether the resource class is complete.

If it was helpful to you, please give it a like and leave?

Guess you like

Origin blog.csdn.net/zhao8856234/article/details/111031926