Skip to content

Instantly share code, notes, and snippets.

@jpzhu
Last active December 26, 2015 07:19
Show Gist options
  • Save jpzhu/7114588 to your computer and use it in GitHub Desktop.
Save jpzhu/7114588 to your computer and use it in GitHub Desktop.
java lib shared
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_SDK_VERSION := current
LOCAL_JAVA_LIBRARIES := hellolib
LOCAL_PACKAGE_NAME := HelloTTT
include $(BUILD_PACKAGE)
# Copyright 2008 The Android Open Source Project
#
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_MODULE := hellolib
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)
include $(BUILD_JAVA_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := hellolib.xml
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/permissions
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)
<?xml version="1.0" encoding="utf-8"?>
<!--
This software is in the public domain, furnished "as is", without technical
support, and with no warranty, express or implied, as to its usefulness for
any purpose.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.igdium.helloworld2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".HelloWorldAndroidActivity"
android:label="@string/app_name" >
<uses-library android:name="com.jpzhu.hellolib" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.jpzhu.hellolib" />
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<permissions>
<library name="com.jpzhu.hellolib"
file="/system/framework/hellolib.jar" />
</permissions>
  1. 编译javalib时需要指明编译类型为BUILD_JAVA_LIBRARY。 所以在Android.mk中需要include $(BUILD_JAVA_LIBRARY)

  2. 生成一个javalib的共享库时,需要提供一个permission文件放到 /system/etc/permissions 目录下,用于其它使用该库的app能够查询到该共享.jar文件。内容参考hellolib.xml.

  3. 编译javaapp的,需要在AndroidManifest.xml里指明使用了该java库。 其中android:name需要指明的名字是javalib里的package名。

  4. java app的Android.mk里需要指明应用了哪个库名。 LOCAL_JAVA_LIBRARIES := hellolib

当permission文件被拷贝至设备时,需重启方能生效

参考: http://hi.baidu.com/gaogaf/item/cef2285e2372bb444fff2046

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment