Thursday, March 27, 2014

Compile APK with static java lib or java lib in AOSP

1. Create a folder("Myproject") under ANDROID_ROOT/packages/apps/
2. Before compile APK. Make sure compile all reference library first.
3.1 Part of make file example with local_java_library
 
     LOCAL_JAVA_LIBRARIES := com.sample.mylocallib

3.2 Part of make file example with local_static_java_library
   
    LOCAL_STATIC_JAVA_LIBRARIES := com.sample.mystaticlib
    LOCAL_PROGUARD_ENABLED := disabled

4. Proguard will remove unreferenced code by default. So if APK want keep all code, it may need to set proguard disabled. Or enable proguard and keep class in proguard setting
 
     Make file example:
     LOCAL_PROGUARD_ENABLED := custom
     LOCAL_PROGUARD_FLAG_FILES := proguard.flags

     proguard.flags example:
     -keep class com.sample.mystaticlib.** { *; }
     -keep interface com.sample.mystaticlib.interface.** { *; }

5. If get error "can't find xxxx/classes.jar" when compile APK. It may add classpath in make file
   
   Make file example:
    LOCAL_CLASSPATH := out/target/common/obj/JAVA_LIBRARIES/libmyinterface_intermediates/classes.jar

No comments:

Post a Comment