Export android library project for reuse without source code

后端 未结 2 723
夕颜
夕颜 2021-01-03 11:13

I need to export a library project without the source code for security reasons. Unfortunately the jar file generated within a library project does not contain the resources

2条回答
  •  悲&欢浪女
    2021-01-03 11:44

    The following recipe used to work, though I have not tried it very recently:

    Step #1: Get the library project working as-is. I will refer to the directory holding this project as $ORIG.

    Step #2: If you have not done so already, create your Ant build scripts in $ORIG using android update project.

    Step #3: Add a task to $ORIG/build.xml that creates a JAR file, something like:

    
      
    
    

    Step #4: Copy your entire library project from $ORIG into another directory, which I'll call $DIST.

    Step #5: Get rid of the src/ tree in $DIST except for the root src/ directory itself.

    Step #6: Move bin/YOUR-LIBRARY-NAME-GOES-HERE.jar into $DIST/libs/. This effectively replaces your source code from src/ with its compiled equivalent.

    Step #7: Get rid of $DIST/bin/ as it is no longer needed.

    $DIST now holds an Android library project that is the equivalent of $ORIG, except that the src/ tree is replaced by libs/YOUR-LIBRARY-NAME-GOES-HERE.jar.

    Since the Google Play Services package from the SDK Manager is packaged this way, not only do I assume the recipe still works, but it would appear to be reasonably officially endorsed.

    Note that there is new build system in the works that may give us more options here. If you are reading this question in, say, 2014, be sure to check to see if there are better alternatives.

提交回复
热议问题