Question

I almost found the answer in Adding a external jar reference in Android.mk but I'm still not quite there.

My project contains commons-io-2.4.jar and jsch-0.1.49.jar in the libs/ directory. Everything builds beautifully in eclipse. Now I want to write an Android.mk file to build my project automatically.

My Android.mk looks like this, but it's not working.

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_PACKAGE_NAME := MyProject
LOCAL_CERTIFICATE := platform

LOCAL_STATIC_JAVA_LIBRARIES := jsch-0.1.49 commons-io-2.4

LOCAL_PROGUARD_FLAGS      := -include $(LOCAL_PATH)/proguard.flags

include $(BUILD_PACKAGE)

LOCAL_STATIC_JAVA_LIBRARIES := libs
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libs:jsch-0.1.49 libs:commons-io-2.4

include $(BUILD_MULTI_PREBUILT)

I'm sure there's just a little secret sauce I've gotten wrong, but I can't figure it out.

Is there a good reference for Android.mk files? All I could find were recipes for working with the ndk.

Was it helpful?

Solution

OK, a couple hours of googling and experimenting seems to have found the solution.
Documenting it here for others to find:

The key was to

  1. Define LOCAL_STATIC_JAVA_LIBRARIES with a symbolic name for the library I want to include, e.g. libjsch
  2. Execute CLEAR_VARS (why?)
  3. Define LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES as libjsch:<path-to-jar-file>
  4. Include BUILD_MULTI_PREBUILT.

(Testing showed that any symbolic name (e.g. "foo") works fine, as long as it matches in the two declarations.)

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_PACKAGE_NAME := MyProject

LOCAL_STATIC_JAVA_LIBRARIES := libjsch

include $(BUILD_PACKAGE)

include $(CLEAR_VARS)

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libjsch:libs/jsch-0.1.49.jar

include $(BUILD_MULTI_PREBUILT)

OTHER TIPS

Thanks a ton Edward Falk. I have just resolved my problem with answer u have given me thanks again here is my code. The Keyword "lib" is a night mare.

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := $(call all-subdir-java-files)

LOCAL_PACKAGE_NAME := MDM

LOCAL_STATIC_JAVA_LIBRARIES := libandroid-async-http libgcm libjson-simple


LOCAL_JAVA_LIBRARIES += telephony-common mms-common

LOCAL_CERTIFICATE := platform

include $(BUILD_PACKAGE)

include $(CLEAR_VARS)

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libandroid-async-http:libs/android-async-http-1.4.4.jar libgcm:libs/gcm.jar  libjson-simple:libs/json-simple-1.1.1.jar 

include $(BUILD_MULTI_PREBUILT)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top