Java resource files are missing when I build my android library with gradle and proguard

Question!

the java resources are packed to the jar without any problem when I do a debug build. However, it doesn't work with release builds. I noticed that the gradle task processReleaseJavaRes is only executed for debug builds. I searched the android gradle code and found the following lines of code:

if (variantConfig.buildType.runProguard) {
    // run proguard on output of compile task
    createProguardTasks(variantData, null)
    // hack since bundle can't depend on variantData.proguardTask
    mergeProGuardFileTask.dependsOn variantData.proguardTask
    bundle.dependsOn packageRes, packageAidl, packageRenderscript, mergeProGuardFileTask, lintCopy, variantData.ndkCompileTask
} else {
    Sync packageLocalJar = project.tasks.create("package${variantData.variantConfiguration.fullName.capitalize()}LocalJar",Sync)
    packageLocalJar.from(getLocalJarFileList(variantData.variantDependency))
    packageLocalJar.into(project.file("$project.buildDir/$DIR_BUNDLES/${variantData.variantConfiguration.dirName}/$SdkConstants.LIBS_FOLDER"))
    // jar the classes.
    Jar jar = project.tasks.create("package${buildType.name.capitalize()}Jar", Jar);
    jar.dependsOn variantData.javaCompileTask, variantData.processJavaResourcesTask
    jar.from(variantData.javaCompileTask.outputs);
    jar.from(variantData.processJavaResourcesTask.destinationDir)
    ...
    bundle.dependsOn packageRes, jar, packageAidl, packageRenderscript, packageLocalJar, mergeProGuardFileTask, lintCopy, variantData.ndkCompileTask
    ...
}

I then tried to add the task as a dependecy of proguardRelease:

tasks.whenTaskAdded { task ->
    if (task.name.matches("proguardRelease")) {
        task.dependsOn('processReleaseJavaRes')
    }
}

This works great and the java resources were created in build/intermediates/javaResources/ - but then the next problem occured. How can I tell proguard that it should build the jar with the classes from build/intermediates/classes and also include the resources from build/intermediates/javaResources? I tried to set the javaResources path with -injars. Now they are added to proguard (see log output below), but are not added to the classes.jar in build/intermediate/bundles/release/classes.jar.

13:32:30.731 [INFO] [system.out] Reading program directory [/path/to/my/project/build/intermediates/classes/release] (filtered)
13:32:30.913 [INFO] [system.out] Reading program directory [/path/to/my/project/build/intermediates/javaResources/release]

Thanks in advance, Romanski

By : Romanski


Answers

I haven't found a solution, but I made a workaround for the problem: I just run the task manually and then create a jar from the java resources and the obfuscated jar file:

android.libraryVariants.all { variant -
By : Romanski


This video can help you solving your question :)
By: admin