Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a jar file from libs/ to Android.mk

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.

like image 417
Edward Falk Avatar asked Dec 11 '12 22:12

Edward Falk


1 Answers

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)
like image 197
Edward Falk Avatar answered Dec 03 '22 21:12

Edward Falk