Adding a jar file from libs/ to Android.mk
Asked Answered
S

2

7

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.

Sombrous answered 11/12, 2012 at 22:19 Comment(3)
You can find a good reference regarding how AOSP build system works: kandroid.org/online-pdk/guide/build_cookbook.htmlFerreira
Above link no longer works.Samira
wladimir-tm4pda.github.io/porting/build_cookbook.html might be the same thing.Sombrous
S
23

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)
Sombrous answered 11/12, 2012 at 23:50 Comment(3)
how can I add .aar files in android.mk ?Gyration
@Gyration It's the same process as this answer, just replace LOCAL_STATIC_JAVA_LIBRARIES with LOCAL_STATIC_JAVA_AAR_LIBRARIESErs
can you please say how to import libjsch:libs like import .....?Shamikashamma
N
7

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)
Navigate answered 15/10, 2015 at 8:47 Comment(1)
can you please say how to import json-simple like import .....?Shamikashamma

© 2022 - 2024 — McMap. All rights reserved.