问题
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. I cannot expect the users of this library to deal with any resources needed by the library.
There have been similar post to this one, but I am yet to see a solution.
回答1:
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:
<target name="jar" depends="debug">
<jar
destfile="bin/YOUR-LIBRARY-NAME-GOES-HERE.jar"
basedir="bin/classes"
/>
</target>
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.
回答2:
One idea I've heard mention of is using a regular Library project with a reference to a Jar file which is where you would put all of your proprietary code. All of the assets would need to be in your library project and would be readable by the users of your library. Keep in mind that anyone with apktool can extract these files from the final APK anyways.
However, the code in the JAR would not be readable and your users would need to reverse engineer them which can be difficult, especially if you obfuscate it.
来源:https://stackoverflow.com/questions/14075760/export-android-library-project-for-reuse-without-source-code