Repository: umeng/apf
Branch: master
Commit: 3a43f732f4ed
Files: 34
Total size: 43.3 KB
Directory structure:
gitextract_wi3u2aqj/
├── .gitignore
├── README.md
├── apf-framework.jar
├── apf-plugin-build/
│ ├── ant.properties.example
│ ├── apf-create-plugin.sh
│ ├── build.xml.plugin.example
│ ├── build.xml.plugin.ifs.example
│ └── debug.keystore
├── com.example.host/
│ ├── .settings/
│ │ └── org.eclipse.core.resources.prefs
│ ├── AndroidManifest.xml
│ ├── libs/
│ │ └── apf-framework.jar
│ ├── proguard.cfg
│ ├── project.properties
│ ├── res/
│ │ ├── layout/
│ │ │ ├── main.xml
│ │ │ └── second.xml
│ │ └── values/
│ │ └── strings.xml
│ └── src/
│ └── com/
│ └── example/
│ └── host/
│ └── MainActivity.java
├── com.example.plugin1/
│ ├── AndroidManifest.xml
│ ├── ant.properties
│ ├── build.xml
│ ├── proguard-project.txt
│ ├── project.properties
│ ├── res/
│ │ ├── layout/
│ │ │ └── main.xml
│ │ └── values/
│ │ └── strings.xml
│ └── src/
│ └── com/
│ └── example/
│ └── plugin1/
│ ├── ExampleApfServiceImpl.java
│ └── PluginActivity.java
└── com.example.plugin1.ifs/
├── AndroidManifest.xml
├── ant.properties
├── build.xml
├── proguard-project.txt
├── project.properties
├── res/
│ ├── layout/
│ │ └── main.xml
│ └── values/
│ └── strings.xml
└── src/
└── com/
└── example/
└── plugin1/
└── ifs/
└── ExampleApfService.java
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
# Eclipse project files
.classpath
.project
================================================
FILE: README.md
================================================
# Android Plugin Framework
> This project is pre-mature and may be changed very frequently.
## Introduction
Android Plugin Framework (APF) aims to providing a flexible, extensible framework, for Android applications, like OSGi for Java applications. App developers can design their Android applications in a totally new way: declar the interface of a application component, put the actual implementations of the component on the remote server, use APF library to load the actual implementations at runtime. In this way, app developers can dynamically update application components, or add features to an already installed application, without requiring the application being updated throught Android System Framework. A typical usage scenario can be skin: designers design various skins for an application according to pre-defined format and then put those skin files online. App users can then find and use skins through `skin store`, without having to installing a new version of the app.
Another using scenario is for game design: design the `hard` level of a game in a different package that can be dynamically load into the game. When an user passes the `low` level of the game, the app can load the `hard` level of game code using APF dynamically. The user gets a seemlessly upgrade experience.
The project consists 3 major components:
### APF core
The core library to find, verify and load plugin code from remote servers. Now, the architecture and the remote server is still pre-mature and is subject to change, so it is not open sourced yet. But it will be soon.
### Plugin Build Scripts
The instructions to create your own plugins. Check [Creating Your APF Plugin] for details.
### Example
Example contains:
1. Host application, Android Application Project.
2. Plugin Interface, as an Android Library Project
3. Plugin Implementation, as an Android Application Project
There is already an example plugin implementation signed by [Umeng](http://www.umeng.com) and hosted on [Umeng](http://www.umeng.com)'s server side. If you want to try it out and have a different implementation, please contact xuxianming @ umeng.com
## Creating Your APF Plugin
To create a effective APD plugin, you will need to design plugin interface first in an Android Library Project. Next, implement the declared interface in an Android Application Project.
### Plugin Interface
* Create an Android Library Project.
```bash
android create lib-project -n com_example_plugin1_ifs -t android-17 -k com.example.plugin1.ifs -p com.example.plugin1.ifs
```
* Update ant.properties according to the template file `apf-plugin-build/ant.properties.example`
```bash
/apf-opensource/com.example.plugin1$ cat ../apf-plugin-build/ant.properties.example >> ant.properties
```
The `ant.properties` looks like:
```bash
# This file is used to override default values used by the Ant build system.
#
# This file must be checked into Version Control Systems, as it is
# integral to the build system of your project.
# This file is only used by the Ant script.
# You can use this to override default values such as
# 'source.dir' for the location of your java source folder and
# 'out.dir' for the location of your output folder.
# You can also use it define how the release builds are signed by declaring
# the following properties:
# 'key.store' for the location of your keystore and
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.
key.store=../apf-plugin-build/debug.keystore
key.store.password=android
key.alias=androiddebugkey
key.alias.password=android
```
* Update `build.xml` according to the template file `build.xml.plugin.ifs.example`
```bash
apf-opensource/com.example.plugin1.ifs$ cp ../apf-plugin-build/build.xml.plugin.ifs.example build.xml
```
* Design the interface to be used by the host application. Check: `src/com/example/plugin1/ifs/`
### Plugin Implementation
* Create an Android Application Project.
```bash
android create project -n com_example_plugin1 -t android-17 -k com.example.plugin1 -p com.example.plugin1 -a PluginActivity
cd com.example.plugin1
android update project -p ./ --library ../com.example.plugin1.ifs
```
* Update ant.properties according to the template file `ant.properties.example`
* Update `build.xml` according to the template file `build.xml.plugin.ifs.example`
```bash
apf-opensource/com.example.plugin1$ cp ../apf-plugin-build/build.xml.plugin.example build.xml
```
* Design the interface to be used by the host application.
`src/com/example/plugin1/ifs/`
> `Plugin Implementation` project will be will packaged/exported as `${package-name}.apk` and `Plugin Interface` project will be packaged to `${package-name}.ifs.jar`.
For example, `com.umeng.analytics.apk` for plugin, and `com.umeng.analytics.ifs.jar` for interfaces declarations.
### Build
```bash
> ant deploy
```
The output will be at `${project.dir}/bin/com.example.plugina.apk` and `${project.dir}/bin/com.example.plugina.ifs.jar`.
> Note: if the plugin implementation projec ifself is a android library project, for example, like com.umeng.common, you need a little "hack" to the ant build system. First change ant.properties, change `android.library=true` to `android.library=false`. After successfully `ant deploy`, change it back to `android.library=true`, as is required by the upper stream application project.
### Example
See [com.example.host] and [com.example.plugin1].
To Run the example:
```bash
ant
```
## Signing plugin
All plugins must be signed with private key. APF adopts similar mechanisms as Android app signing. See [Signing Your Applications](http://developer.android.com/tools/publishing/app-signing.html) for help.
### Sign the plugin apk
1. Make sure that you can build your plugin interface and implementation with `ant` successfully before preceeding.
2. Configure `ant.properties`. Add the content of `ant.properties.example` to your plugin implementation project's `ant.properties`.
3. Use `ant deploy` to build the release apk package.
This will build a *release* mode plugin apk called *[project-name]-release.apk* under bin/ directory.
### Warning
> When to release your plugin, remember to update the key and keystore. Do not use the example key store used here.
> Caution: Since APF is in very pre-mature state, it's architecture and server side design is subject to change very frequently. For now, APF provided by [Umeng](http://www.umeng.com) does not allow any plugin signed by third party. If you want to try this out and want to deploy your plugin on [Umeng](http://www.umeng.com)'s platform, please develop your plugin first and contact us. After we check out that your plugin is secure, we can sign the plugin for you and host your plugin on [Umeng](http://www.umeng.com)'s server. Please email to xuxianming at umeng.com.
We will open source implementation of APF when it's architecture design is freezed.
================================================
FILE: apf-plugin-build/ant.properties.example
================================================
key.store=../apf-plugin-build/debug.keystore
key.store.password=android
key.alias=androiddebugkey
key.alias.password=android
================================================
FILE: apf-plugin-build/apf-create-plugin.sh
================================================
#!bin/sh
# input: name of interface: com.example.plugin.ifs
# create android lib project.
android create lib-project $
# create android application project implementing the interface
android create project
android update project
# update build.xml for plugin and its implementation
# create host example.
================================================
FILE: apf-plugin-build/build.xml.plugin.example
================================================
executable="${dx}" output="${intermediate.dex.file}" nolocals="@{nolocals}" forceJumbo="${dex.force.jumbo}" disableDexMerger="true" verbose="true"
================================================
FILE: apf-plugin-build/build.xml.plugin.ifs.example
================================================
Android Ant Build. Available targets:
deploy: Build library jar file. The generated output is at "${out.absolute.dir}/com.umeng.apf.jar"
clean: Removes output files created by other targets.
================================================
FILE: com.example.host/.settings/org.eclipse.core.resources.prefs
================================================
#Fri Jul 20 17:17:22 CST 2012
eclipse.preferences.version=1
encoding/=UTF-8
================================================
FILE: com.example.host/AndroidManifest.xml
================================================
================================================
FILE: com.example.host/proguard.cfg
================================================
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native ;
}
-keepclasseswithmembers class * {
public (android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public (android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
================================================
FILE: com.example.host/project.properties
================================================
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.
# Project target.
target=android-16
android.library.reference.1=../com.example.plugin1.ifs
================================================
FILE: com.example.host/res/layout/main.xml
================================================
"
================================================
FILE: com.example.host/res/layout/second.xml
================================================
================================================
FILE: com.example.host/res/values/strings.xml
================================================
Hello World, TestUmengSdkActivity!APF Example HostCheckGo
================================================
FILE: com.example.host/src/com/example/host/MainActivity.java
================================================
package com.example.host;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import com.example.plugin1.ifs.ExampleApfService;
import com.umeng.apf.ApfException;
import com.umeng.apf.PluginManager;
public class MainActivity extends Activity {
private static final String TAG = MainActivity.class.getName();
private ExampleApfService service;
EditText edit_a;
EditText edit_b;
TextView result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d(TAG, "onCreate");
//
new Thread() {
@Override
public void run() {
try {
PluginManager.registerPlugin("com.example.plugin1");
PluginManager.loadPlugins(getApplicationContext());
service = (ExampleApfService) PluginManager
.newInstance("com.example.plugin1.ExampleApfServiceImpl");
if (service == null)
throw new ApfException("unable to initialize plugin");
} catch (ApfException e) {
e.printStackTrace();
}
}
}.start();
edit_a = (EditText) findViewById(R.id.edit_a);
edit_b = (EditText) findViewById(R.id.edit_b);
result = (TextView) findViewById(R.id.text_result);
this.findViewById(R.id.button_add).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
int a = Integer.parseInt(edit_a.getText().toString());
int b = Integer.parseInt(edit_b.getText().toString());
if (service != null) {
result.setText(service.add(a, b));
}
}
});
this.findViewById(R.id.button_minus).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
int a = Integer.parseInt(edit_a.getText().toString());
int b = Integer.parseInt(edit_b.getText().toString());
if (service != null) {
result.setText(service.minus(a, b));
}
}
});
this.findViewById(R.id.button_multiply).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
int a = Integer.parseInt(edit_a.getText().toString());
int b = Integer.parseInt(edit_b.getText().toString());
if (service != null) {
result.setText(service.multiply(a, b));
}
}
});
this.findViewById(R.id.button_divide).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
int a = Integer.parseInt(edit_a.getText().toString());
int b = Integer.parseInt(edit_b.getText().toString());
if (service != null) {
result.setText(service.divide(a, b));
}
}
});
}
@Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause");
}
@Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume");
}
}
================================================
FILE: com.example.plugin1/AndroidManifest.xml
================================================
================================================
FILE: com.example.plugin1/ant.properties
================================================
# This file is used to override default values used by the Ant build system.
#
# This file must be checked into Version Control Systems, as it is
# integral to the build system of your project.
# This file is only used by the Ant script.
# You can use this to override default values such as
# 'source.dir' for the location of your java source folder and
# 'out.dir' for the location of your output folder.
# You can also use it define how the release builds are signed by declaring
# the following properties:
# 'key.store' for the location of your keystore and
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.
key.store=../apf-plugin-build/debug.keystore
key.store.password=android
key.alias=androiddebugkey
key.alias.password=android
================================================
FILE: com.example.plugin1/build.xml
================================================
executable="${dx}" output="${intermediate.dex.file}" nolocals="@{nolocals}" forceJumbo="${dex.force.jumbo}" disableDexMerger="true" verbose="true"
================================================
FILE: com.example.plugin1/proguard-project.txt
================================================
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
================================================
FILE: com.example.plugin1/project.properties
================================================
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-17
android.library.reference.1=../com.example.plugin1.ifs
================================================
FILE: com.example.plugin1/res/layout/main.xml
================================================
================================================
FILE: com.example.plugin1/res/values/strings.xml
================================================
PluginActivity
================================================
FILE: com.example.plugin1/src/com/example/plugin1/ExampleApfServiceImpl.java
================================================
package com.example.plugin1;
import android.util.Log;
/**
* Implementation of plugin interface
* {@link com.example.plugin1.ifs.ExampleApfService}
*
* @author lucas
*
*/
public class ExampleApfServiceImpl implements
com.example.plugin1.ifs.ExampleApfService {
private static final String TAG = ExampleApfServiceImpl.class.getName();
/**
* Flawed implementation, mind overflow.
*/
@Override
public int add(int a, int b) {
Log.d(TAG, "calling implementation add.");
return a + b;
}
@Override
public int minus(int a, int b) {
Log.d(TAG, "calling implementation minus.");
return a - b;
}
/**
* Flawed implementation of {@link #multiply(int, int)}. Mind overflow.
*/
@Override
public int multiply(int a, int b) {
Log.d(TAG, "calling implementation multiply.");
return a * b;
}
/**
* Flawed implementation, mind divided by zero.
*/
@Override
public int divide(int a, int b) {
Log.d(TAG, "calling implementation divide.");
return a / b;
}
}
================================================
FILE: com.example.plugin1/src/com/example/plugin1/PluginActivity.java
================================================
package com.example.plugin1;
import android.app.Activity;
import android.os.Bundle;
public class PluginActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
================================================
FILE: com.example.plugin1.ifs/AndroidManifest.xml
================================================
================================================
FILE: com.example.plugin1.ifs/ant.properties
================================================
# This file is used to override default values used by the Ant build system.
#
# This file must be checked into Version Control Systems, as it is
# integral to the build system of your project.
# This file is only used by the Ant script.
# You can use this to override default values such as
# 'source.dir' for the location of your java source folder and
# 'out.dir' for the location of your output folder.
# You can also use it define how the release builds are signed by declaring
# the following properties:
# 'key.store' for the location of your keystore and
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.
key.store=../apf-plugin-build/debug.keystore
key.store.password=android
key.alias=androiddebugkey
key.alias.password=android
================================================
FILE: com.example.plugin1.ifs/build.xml
================================================
Android Ant Build. Available targets:
deploy: Build library jar file. The generated output is at "${out.absolute.dir}/com.umeng.apf.jar"
clean: Removes output files created by other targets.
================================================
FILE: com.example.plugin1.ifs/proguard-project.txt
================================================
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
================================================
FILE: com.example.plugin1.ifs/project.properties
================================================
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
android.library=true
# Project target.
target=android-17
================================================
FILE: com.example.plugin1.ifs/res/layout/main.xml
================================================
================================================
FILE: com.example.plugin1.ifs/res/values/strings.xml
================================================
ACTIVITY_ENTRY_NAME
================================================
FILE: com.example.plugin1.ifs/src/com/example/plugin1/ifs/ExampleApfService.java
================================================
package com.example.plugin1.ifs;
/**
* Example APF Plugin interface. Declar the interface methods here and implement
* the interface in project .com.example.plugin1
*
* @author lucas
*
*/
public interface ExampleApfService {
public int add(int a, int b);
public int minus(int a, int b);
public int multiply(int a, int b);
public int divide(int a, int b);
}