├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── libraries
│ ├── junit_4_12.xml
│ ├── support_annotations_23_4_0.xml
│ ├── hamcrest_core_1_3.xml
│ ├── support_annotations_24_0_0.xml
│ ├── support_vector_drawable_24_0_0.xml
│ ├── animated_vector_drawable_24_0_0.xml
│ ├── support_vector_drawable_23_4_0.xml
│ ├── animated_vector_drawable_23_4_0.xml
│ ├── appcompat_v7_24_0_0.xml
│ ├── support_v4_24_0_0.xml
│ ├── appcompat_v7_23_4_0.xml
│ └── support_v4_23_4_0.xml
├── runConfigurations.xml
├── modules.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── activity_load.xml
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── dynamicloader
│ │ │ │ ├── Constants.java
│ │ │ │ ├── BaseActivity.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── RefInvoke.java
│ │ │ │ └── LoadActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── dynamicloader
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── dynamicloader
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── silentinstaller
├── .gitignore
├── 5.0
│ ├── SignApk.jar
│ ├── platform.pk8
│ └── platform.x509.pem
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── aidl
│ │ │ └── android
│ │ │ │ └── content
│ │ │ │ └── pm
│ │ │ │ ├── IPackageMoveObserver.aidl
│ │ │ │ ├── IPackageInstallObserver.aidl
│ │ │ │ └── IPackageDeleteObserver.aidl
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── silentinstaller
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── silentinstaller
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── silentinstaller
│ │ └── ApplicationTest.java
├── proguard-rules.pro
├── build.gradle
└── ReadMe.md
├── resourceloaderapk
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ └── values-w820dp
│ │ │ │ └── dimens.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── resourceloaderapk
│ │ │ │ ├── UIUtil.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── resourceloaderapk
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── resourceloaderapk
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── Readme.md
├── .gitignore
├── gradle.properties
├── gradlew.bat
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | DynamicLoader
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/silentinstaller/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/resourceloaderapk/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':resourceloaderapk', ':silentinstaller'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DynamicLoader
3 |
4 |
--------------------------------------------------------------------------------
/silentinstaller/5.0/SignApk.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjianfengnb/DynamicLoadResource/HEAD/silentinstaller/5.0/SignApk.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjianfengnb/DynamicLoadResource/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/silentinstaller/5.0/platform.pk8:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjianfengnb/DynamicLoadResource/HEAD/silentinstaller/5.0/platform.pk8
--------------------------------------------------------------------------------
/silentinstaller/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SilentInstaller
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjianfengnb/DynamicLoadResource/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjianfengnb/DynamicLoadResource/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjianfengnb/DynamicLoadResource/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjianfengnb/DynamicLoadResource/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjianfengnb/DynamicLoadResource/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/silentinstaller/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjianfengnb/DynamicLoadResource/HEAD/silentinstaller/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/silentinstaller/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjianfengnb/DynamicLoadResource/HEAD/silentinstaller/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/silentinstaller/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjianfengnb/DynamicLoadResource/HEAD/silentinstaller/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/silentinstaller/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjianfengnb/DynamicLoadResource/HEAD/silentinstaller/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/silentinstaller/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjianfengnb/DynamicLoadResource/HEAD/silentinstaller/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/resourceloaderapk/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjianfengnb/DynamicLoadResource/HEAD/resourceloaderapk/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/resourceloaderapk/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangjianfengnb/DynamicLoadResource/HEAD/resourceloaderapk/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/resourceloaderapk/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ResourceLoaderApk
3 | 我是在Resource.apk的资源
4 |
5 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/silentinstaller/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/silentinstaller/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/resourceloaderapk/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dynamicloader/Constants.java:
--------------------------------------------------------------------------------
1 | package com.dynamicloader;
2 |
3 | /**
4 | * Created by Jam on 16-8-25
5 | * Description:
6 | */
7 | public class Constants {
8 | public static final String RESOURCE_APK_NAME = "resourceloaderapk-release.apk";
9 | }
10 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/resourceloaderapk/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/resourceloaderapk/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #00FF00
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/test/java/com/dynamicloader/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.dynamicloader;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/resourceloaderapk/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/silentinstaller/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/silentinstaller/src/test/java/com/silentinstaller/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.silentinstaller;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/dynamicloader/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.dynamicloader;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/resourceloaderapk/src/test/java/com/example/resourceloaderapk/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.resourceloaderapk;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/resourceloaderapk/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/silentinstaller/src/androidTest/java/com/silentinstaller/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.silentinstaller;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/silentinstaller/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/resourceloaderapk/src/androidTest/java/com/example/resourceloaderapk/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.example.resourceloaderapk;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/.idea/libraries/junit_4_12.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/support_annotations_23_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/hamcrest_core_1_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/support_annotations_24_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 | ##动态加载另一个APK文件的资源
2 |
3 |
4 | ###知识要点
5 |
6 | - DexClassLoader加载APK文件。
7 |
8 | - 详情需要理解DexClassLoader和PathClassLoader的区别:[Android中插件开发篇之----类加载器 ](http://blog.csdn.net/jiangwei0910410003/article/details/41384667)
9 |
10 |
11 | - 如何将插件APK的资源加载到本地的Resource中,需要用到AssetManager的addAssetPath方法。这个方法可以加载资源目录也可以加载zip,apk就是一个zip文件。
12 |
13 |
14 | ###操作教程
15 | - 运行app module。
16 | - 运行resourceloaderapk module
17 | - 将resourceloaderapk module 生成的apk 重命名为 resource.apk 。名字可以改的,具体看MainActivity代码
18 | - 利用adb 将 resource.apk 移动到 /data/data/packagename/cache 目录下。
19 | - 退出app重新运行
20 |
21 |
22 |
23 | ####静默安装APK的代码在silentinstaller module里面
24 |
25 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 |
39 | # Keystore files
40 | *.jks
41 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/silentinstaller/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "24.0.0"
6 |
7 | defaultConfig {
8 | applicationId "com.dynamicloader"
9 | minSdkVersion 9
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.4.0'
26 | }
27 |
--------------------------------------------------------------------------------
/resourceloaderapk/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/silentinstaller/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "24.0.0"
6 |
7 | defaultConfig {
8 | applicationId "com.silentinstaller"
9 | minSdkVersion 9
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:24.0.0'
26 | }
27 |
--------------------------------------------------------------------------------
/resourceloaderapk/src/main/java/com/example/resourceloaderapk/UIUtil.java:
--------------------------------------------------------------------------------
1 | package com.example.resourceloaderapk;
2 |
3 | import android.content.Context;
4 | import android.graphics.drawable.Drawable;
5 |
6 | /**
7 | * Created by Jam on 16-8-22
8 | * Description:
9 | */
10 | public class UIUtil {
11 |
12 |
13 | public static String getTextString(Context ctx){
14 | return ctx.getResources().getString(R.string.text);
15 | }
16 |
17 | public static Drawable getImageDrawable(Context ctx){
18 | return ctx.getResources().getDrawable(R.mipmap.ic_launcher);
19 | }
20 |
21 | public static int getTextBackgroundId(Context ctx){
22 | return ctx.getResources().getColor(R.color.color_green);
23 | }
24 |
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/resourceloaderapk/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "24.0.0"
6 |
7 | defaultConfig {
8 | applicationId "com.example.resourceloaderapk"
9 | minSdkVersion 9
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.4.0'
26 | }
27 |
--------------------------------------------------------------------------------
/.idea/libraries/support_vector_drawable_24_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/libraries/animated_vector_drawable_24_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/resourceloaderapk/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/silentinstaller/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/libraries/support_vector_drawable_23_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/animated_vector_drawable_23_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/appcompat_v7_24_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/silentinstaller/src/main/aidl/android/content/pm/IPackageMoveObserver.aidl:
--------------------------------------------------------------------------------
1 | /*
2 | **
3 | ** Copyright 2007, The Android Open Source Project
4 | **
5 | ** Licensed under the Apache License, Version 2.0 (the "License");
6 | ** you may not use this file except in compliance with the License.
7 | ** You may obtain a copy of the License at
8 | **
9 | ** http://www.apache.org/licenses/LICENSE-2.0
10 | **
11 | ** Unless required by applicable law or agreed to in writing, software
12 | ** distributed under the License is distributed on an "AS IS" BASIS,
13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | ** See the License for the specific language governing permissions and
15 | ** limitations under the License.
16 | */
17 |
18 |
19 | package android.content.pm;
20 |
21 |
22 | /**
23 | * Callback for moving package resources from the Package Manager.
24 | * @hide
25 | */
26 | oneway interface IPackageMoveObserver {
27 | void packageMoved(in String packageName, int returnCode);
28 | }
29 |
--------------------------------------------------------------------------------
/silentinstaller/src/main/aidl/android/content/pm/IPackageInstallObserver.aidl:
--------------------------------------------------------------------------------
1 | /*
2 | **
3 | ** Copyright 2007, The Android Open Source Project
4 | **
5 | ** Licensed under the Apache License, Version 2.0 (the "License");
6 | ** you may not use this file except in compliance with the License.
7 | ** You may obtain a copy of the License at
8 | **
9 | ** http://www.apache.org/licenses/LICENSE-2.0
10 | **
11 | ** Unless required by applicable law or agreed to in writing, software
12 | ** distributed under the License is distributed on an "AS IS" BASIS,
13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | ** See the License for the specific language governing permissions and
15 | ** limitations under the License.
16 | */
17 |
18 |
19 | package android.content.pm;
20 |
21 |
22 | /**
23 | * API for installation callbacks from the Package Manager.
24 | * @hide
25 | */
26 | oneway interface IPackageInstallObserver {
27 | void packageInstalled(in String packageName, int returnCode);
28 | }
29 |
--------------------------------------------------------------------------------
/silentinstaller/src/main/aidl/android/content/pm/IPackageDeleteObserver.aidl:
--------------------------------------------------------------------------------
1 | /*
2 | **
3 | ** Copyright 2007, The Android Open Source Project
4 | **
5 | ** Licensed under the Apache License, Version 2.0 (the "License");
6 | ** you may not use this file except in compliance with the License.
7 | ** You may obtain a copy of the License at
8 | **
9 | ** http://www.apache.org/licenses/LICENSE-2.0
10 | **
11 | ** Unless required by applicable law or agreed to in writing, software
12 | ** distributed under the License is distributed on an "AS IS" BASIS,
13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | ** See the License for the specific language governing permissions and
15 | ** limitations under the License.
16 | */
17 |
18 |
19 | package android.content.pm;
20 |
21 |
22 | /**
23 | * API for deletion callbacks from the Package Manager.
24 | *
25 | * {@hide}
26 | */
27 | oneway interface IPackageDeleteObserver {
28 | void packageDeleted(in String packageName, in int returnCode);
29 | }
30 |
--------------------------------------------------------------------------------
/.idea/libraries/support_v4_24_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/libraries/appcompat_v7_23_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_load.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
21 |
22 |
23 |
31 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/silentinstaller/ReadMe.md:
--------------------------------------------------------------------------------
1 | ###静默安装Demo运行教程
2 |
3 | ####运行环境
4 | `Android API 21` 的模拟器,一定要`Android API 21`的模拟器,因为不同的`API LEVEL` 需要不同的签名文件,我这里只是提供了`API 21` 的签名文件
5 |
6 | ###安装部署
7 | 前期准备,需要静默安装的APK文件,修改名字为`autoinstall.apk`(这个名称是我在`MainActivity`里面写死的,如果要改名的话,可以自己改代码)
8 |
9 | 打开AndroidStudio`,导入工程之后。
10 |
11 | 然后把这个`autoinstall.apk` 放到 `silentinstaller` 的 5.0目录下。
12 |
13 | 然后`AndroidStudio ->Build ->Build APK` 生成apk到 `/silentinstaller/build/outputs/apk/` 目录下。
14 |
15 | 把`silentinstaller-debug-unaligned.apk` 拷贝到 `/silentinstaller/5.0` 目录下
16 |
17 | 打开`Studio` 的`Terminal`执行下面命令:
18 |
19 | 进入5.0目录
20 |
21 | cd 5.0
22 |
23 | 对`silentinstaller-debug-unaligned.apk` 签名,签名后生成的文件为 `silentinstaller.apk`
24 |
25 | java -jar SignApk.jar platform.x509.pem platform.pk8 silentinstaller-debug-unaligned.apk silentinstaller.apk
26 |
27 | 把`autoinstall.apk` 和 `silentinstaller.apk` 拷贝到模拟器中的 `/data/app/`目录
28 |
29 | adb push autoinstall.apk /data/app/
30 | adb push silentinstaller.apk /data/app/
31 |
32 | 进入adb shell
33 |
34 | adb shell
35 |
36 | 安装`silentinstaller.apk`
37 |
38 | pm install -r /data/app/silentinstaller.apk
39 |
40 |
41 | 在模拟器中运行 silentinstaller 程序,点击按钮 查看logcat 在回到模拟器home界面,发现你的 autoinstall.apk已经安装完毕。
42 |
43 |
--------------------------------------------------------------------------------
/.idea/libraries/support_v4_23_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/silentinstaller/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/resourceloaderapk/src/main/java/com/example/resourceloaderapk/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.resourceloaderapk;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.widget.Toast;
8 |
9 | public class MainActivity extends AppCompatActivity {
10 | public static final String TAG = "Resource_MainActivity";
11 | private static View parentView;
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | // Log.i(TAG, "layoutId = " + R.layout.activity_main);
16 | // setContentView(R.layout.activity_main);
17 | if(parentView == null){
18 | setContentView(R.layout.activity_main);
19 | }else{
20 | setContentView(parentView);
21 | }
22 | }
23 |
24 | public static void setLayoutView(View view){
25 | parentView = view;
26 | }
27 |
28 | @Override
29 | protected void onResume() {
30 | super.onResume();
31 | Log.i(TAG, "resource activity onResume");
32 | }
33 |
34 | @Override
35 | protected void onStart() {
36 | super.onStart();
37 | Log.i(TAG, "resource activity onStart");
38 | }
39 |
40 | @Override
41 | protected void onStop() {
42 | super.onStop();
43 | Log.i(TAG, "resource activity onStop");
44 |
45 | }
46 |
47 | @Override
48 | protected void onPause() {
49 | super.onPause();
50 | Log.i(TAG, "resource activity onPause");
51 | }
52 |
53 | @Override
54 | protected void onDestroy() {
55 | super.onDestroy();
56 | Log.i(TAG, "resource activity onDestroy");
57 | }
58 |
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/silentinstaller/5.0/platform.x509.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIEqDCCA5CgAwIBAgIJALOZgIbQVs/6MA0GCSqGSIb3DQEBBAUAMIGUMQswCQYD
3 | VQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4g
4 | VmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UE
5 | AxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTAe
6 | Fw0wODA0MTUyMjQwNTBaFw0zNTA5MDEyMjQwNTBaMIGUMQswCQYDVQQGEwJVUzET
7 | MBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4G
8 | A1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9p
9 | ZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTCCASAwDQYJKoZI
10 | hvcNAQEBBQADggENADCCAQgCggEBAJx4BZKsDV04HN6qZezIpgBuNkgMbXIHsSAR
11 | vlCGOqvitV0Amt9xRtbyICKAx81Ne9smJDuKgGwms0sTdSOkkmgiSQTcAUk+fArP
12 | GgXIdPabA3tgMJ2QdNJCgOFrrSqHNDYZUer3KkgtCbIEsYdeEqyYwap3PWgAuer9
13 | 5W1Yvtjo2hb5o2AJnDeoNKbf7be2tEoEngeiafzPLFSW8s821k35CjuNjzSjuqtM
14 | 9TNxqydxmzulh1StDFP8FOHbRdUeI0+76TybpO35zlQmE1DsU1YHv2mi/0qgfbX3
15 | 6iANCabBtJ4hQC+J7RGQiTqrWpGA8VLoL4WkV1PPX8GQccXuyCcCAQOjgfwwgfkw
16 | HQYDVR0OBBYEFE/koLPdnLop9x1yh8Tnw48ghsKZMIHJBgNVHSMEgcEwgb6AFE/k
17 | oLPdnLop9x1yh8Tnw48ghsKZoYGapIGXMIGUMQswCQYDVQQGEwJVUzETMBEGA1UE
18 | CBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMH
19 | QW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAG
20 | CSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbYIJALOZgIbQVs/6MAwGA1Ud
21 | EwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADggEBAFclUbjZOh9z3g9tRp+G2tZwFAAp
22 | PIigzXzXeLc9r8wZf6t25iEuVsHHYc/EL9cz3lLFCuCIFM78CjtaGkNGBU2Cnx2C
23 | tCsgSL+ItdFJKe+F9g7dEtctVWV+IuPoXQTIMdYT0Zk4u4mCJH+jISVroS0dao+S
24 | 6h2xw3Mxe6DAN/DRr/ZFrvIkl5+6bnoUvAJccbmBOM7z3fwFlhfPJIRc97QNY4L3
25 | J17XOElatuWTG5QhdlxJG3L7aOCA29tYwgKdNHyLMozkPvaosVUz7fvpib1qSN1L
26 | IC7alMarjdW4OZID2q4u1EYjLk/pvZYTlMYwDlE448/Shebk5INTjLixs1c=
27 | -----END CERTIFICATE-----
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dynamicloader/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.dynamicloader;
2 |
3 | import java.lang.reflect.Method;
4 |
5 | import android.app.Activity;
6 | import android.content.res.AssetManager;
7 | import android.content.res.Resources;
8 | import android.content.res.Resources.Theme;
9 | import android.os.Bundle;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.util.Log;
12 |
13 | public class BaseActivity extends AppCompatActivity{
14 |
15 | protected AssetManager mAssetManager;//资源管理器
16 | protected Resources mResources;//资源
17 | protected Theme mTheme;//主题
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | }
23 |
24 | protected void loadResources(String dexPath) {
25 | try {
26 | AssetManager assetManager = AssetManager.class.newInstance();
27 | Method addAssetPath = assetManager.getClass().getMethod("addAssetPath", String.class);
28 | addAssetPath.invoke(assetManager, dexPath);
29 | mAssetManager = assetManager;
30 | } catch (Exception e) {
31 | Log.i("inject", "loadResource error:"+Log.getStackTraceString(e));
32 | e.printStackTrace();
33 | }
34 | Resources superRes = super.getResources();
35 | superRes.getDisplayMetrics();
36 | superRes.getConfiguration();
37 | mResources = new Resources(mAssetManager, superRes.getDisplayMetrics(),superRes.getConfiguration());
38 | mTheme = mResources.newTheme();
39 | mTheme.setTo(super.getTheme());
40 | }
41 |
42 | @Override
43 | public AssetManager getAssets() {
44 | return mAssetManager == null ? super.getAssets() : mAssetManager;
45 | }
46 |
47 | @Override
48 | public Resources getResources() {
49 | return mResources == null ? super.getResources() : mResources;
50 | }
51 |
52 | @Override
53 | public Theme getTheme() {
54 | return mTheme == null ? super.getTheme() : mTheme;
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
21 |
22 |
29 |
30 |
41 |
42 |
51 |
52 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.7
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/silentinstaller/src/main/java/com/silentinstaller/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.silentinstaller;
2 |
3 | import android.content.Context;
4 | import android.content.pm.IPackageInstallObserver;
5 | import android.content.pm.PackageManager;
6 | import android.net.Uri;
7 | import android.os.Bundle;
8 | import android.os.RemoteException;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.util.Log;
11 | import android.view.View;
12 |
13 | import java.io.File;
14 |
15 | public class MainActivity extends AppCompatActivity {
16 |
17 | public static final String TAG = "MainActivity";
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_main);
23 | }
24 |
25 | public void install(View v) {
26 | autoInstallApk(this,new File("/data/app/autoinstall.apk"),"com.analysis","Analysis");
27 | }
28 |
29 |
30 | class MyPackageInstallObserver extends IPackageInstallObserver.Stub {
31 | Context ctx;
32 | String appname;
33 | String filename;
34 | String pkname;
35 |
36 | public MyPackageInstallObserver(Context context, String appname, String filename, String pkname) {
37 | this.ctx = context;
38 | this.appname = appname;
39 | this.filename = filename;
40 | this.pkname = pkname;
41 | }
42 |
43 | @Override
44 | public void packageInstalled(String packageName, int returnCode) throws RemoteException {
45 | Log.i(TAG, "packageInstalled returnCode = " + returnCode);
46 | if (returnCode == 1) {
47 | //TODO install success
48 | }
49 |
50 | }
51 | }
52 |
53 | /**
54 | * 静默安装
55 | *
56 | * @param context
57 | * @param packageName
58 | * @param APPName
59 | */
60 | public void autoInstallApk(Context context, File file, String packageName, String APPName) {
61 | Log.i(TAG, "auto install apk packageName = " + packageName + ", fileName = " + file.getAbsolutePath());
62 | int installFlag = 0;
63 | if (!file.exists()) {
64 | //TODO file not exists
65 | Log.i(TAG,"file is not exists :" + file.getAbsolutePath());
66 | return;
67 | }
68 | installFlag |= PackageManager.INSTALL_REPLACE_EXISTING; //
69 | /**
70 | * 在模拟器安装的时候老是返回 -18 ,通过查看PackageManager源码得出,这个码的意思是SDCARD不能安装应用。所以我这里去掉了
71 | */
72 | // if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
73 | // installFlag |= PackageManager.INSTALL_EXTERNAL;
74 | // }
75 | try {
76 | PackageManager pm = context.getPackageManager();
77 | IPackageInstallObserver observer = new MyPackageInstallObserver(context, APPName, file.getAbsolutePath(), packageName);
78 | pm.installPackage(Uri.fromFile(file), observer, installFlag, packageName);
79 | } catch (Exception e) {
80 | Log.getStackTraceString(e);
81 | }
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dynamicloader/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.dynamicloader;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.content.res.AssetManager;
6 | import android.content.res.Resources;
7 | import android.graphics.drawable.Drawable;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.os.Bundle;
10 | import android.util.Log;
11 | import android.view.View;
12 | import android.widget.ImageView;
13 | import android.widget.TextView;
14 |
15 | import java.io.File;
16 | import java.lang.reflect.Method;
17 |
18 | import dalvik.system.DexClassLoader;
19 |
20 | public class MainActivity extends AppCompatActivity {
21 |
22 | TextView textV;
23 | ImageView imgV;
24 | DexClassLoader classLoader;
25 | String filePath;
26 | private AssetManager mAssetManager;
27 | private Resources mResources;
28 | private Resources.Theme mTheme;
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_main);
34 | String fileDir = getCacheDir().getAbsolutePath();
35 | filePath = fileDir + File.separator + Constants.RESOURCE_APK_NAME; //源dex/jar/apk 目录
36 | String fileRelease = getDir("dex", MODE_PRIVATE).getAbsolutePath(); //存放解压出来的dex文件的目录
37 |
38 | //初始化classloader
39 | classLoader = new DexClassLoader(filePath, fileRelease, null, getClassLoader());
40 |
41 | Log.i("Loader", "filePath = " + filePath);
42 | Log.i("Loader", "isExists = " + new File(filePath).exists());
43 | textV = (TextView) findViewById(R.id.textView);
44 | imgV = (ImageView) findViewById(R.id.imageView);
45 | Log.i("Loader", "default classloader = " + getClassLoader());
46 | Log.i("Loader", "other classloader = " + classLoader);
47 | //点击的时候从apk包中获取背景颜色,和图标进行显示
48 | findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
49 | @Override
50 | public void onClick(View v) {
51 | loadResource(filePath);
52 | setContent();
53 | }
54 | });
55 |
56 | findViewById(R.id.loadActivity).setOnClickListener(new View.OnClickListener() {
57 | @Override
58 | public void onClick(View v) {
59 | startActivity(new Intent(MainActivity.this, LoadActivity.class));
60 | }
61 | });
62 | }
63 |
64 |
65 | private void setContent() {
66 | Class clazz = null;
67 | try {
68 | clazz = classLoader.loadClass("com.example.resourceloaderapk.UIUtil");
69 |
70 | //设置文字
71 | Method method = clazz.getMethod("getTextString", Context.class);
72 | String str = (String) method.invoke(null, this);
73 | textV.setText(str);
74 | //设置背景
75 | method = clazz.getMethod("getTextBackgroundId", Context.class);
76 | int color = (int) method.invoke(null, this);
77 | Log.i("Loader", "color = " + color);
78 | textV.setBackgroundColor(color);
79 | //设置图片
80 | method = clazz.getMethod("getImageDrawable", Context.class);
81 | Drawable drawable = (Drawable) method.invoke(null, this);
82 | Log.i("Loader", "drawable =" + drawable);
83 | imgV.setImageDrawable(drawable);
84 |
85 | } catch (Exception e) {
86 | e.printStackTrace();
87 | }
88 | }
89 |
90 | /**
91 | * 此方法的作用是把resource.apk中的资源加载到AssetManager中,
92 | * 然后在重组一个Resources对象,这个Resources对象包括了resource.apk中的资源。
93 | *
94 | * resource.apk 中是使用Context.getResources()获得Resource对象的,
95 | * 所以还要重写一些getResources()方法,返回该Resources对象
96 | *
97 | * @param dexPath
98 | */
99 | protected void loadResource(String dexPath) {
100 | try {
101 | AssetManager assetManager = AssetManager.class.newInstance();
102 | Method method = assetManager.getClass().getMethod("addAssetPath", String.class);
103 | method.invoke(assetManager, dexPath);
104 | mAssetManager = assetManager;
105 | } catch (Exception e) {
106 | e.printStackTrace();
107 | }
108 |
109 | Resources resource = getResources();
110 | // resource.getConfiguration();
111 | // resource.getDisplayMetrics();
112 |
113 | mResources = new Resources(mAssetManager, resource.getDisplayMetrics(), resource.getConfiguration());
114 |
115 | mTheme = mResources.newTheme();
116 | mTheme.setTo(getTheme());
117 | }
118 |
119 | @Override
120 | public AssetManager getAssets() {
121 | return mAssetManager == null ? super.getAssets() : mAssetManager;
122 | }
123 |
124 | @Override
125 | public Resources getResources() {
126 | return mResources == null ? super.getResources() : mResources;
127 | }
128 |
129 | @Override
130 | public Resources.Theme getTheme() {
131 | return mTheme == null ? super.getTheme() : mTheme;
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dynamicloader/RefInvoke.java:
--------------------------------------------------------------------------------
1 | package com.dynamicloader;
2 |
3 | import java.lang.reflect.InvocationTargetException;
4 | import java.lang.reflect.Method;
5 | import java.lang.reflect.Field;
6 |
7 | public class RefInvoke {
8 | /**
9 | * 反射执行类的静态函数(public)
10 | * @param class_name 类名
11 | * @param method_name 函数名
12 | * @param pareTyple 函数的参数类型
13 | * @param pareVaules 调用函数时传入的参数
14 | * @return
15 | */
16 | public static Object invokeStaticMethod(String class_name, String method_name, Class[] pareTyple, Object[] pareVaules){
17 |
18 | try {
19 | Class obj_class = Class.forName(class_name);
20 | Method method = obj_class.getMethod(method_name,pareTyple);
21 | return method.invoke(null, pareVaules);
22 | } catch (SecurityException e) {
23 | // TODO Auto-generated catch block
24 | e.printStackTrace();
25 | } catch (IllegalArgumentException e) {
26 | // TODO Auto-generated catch block
27 | e.printStackTrace();
28 | } catch (IllegalAccessException e) {
29 | // TODO Auto-generated catch block
30 | e.printStackTrace();
31 | } catch (NoSuchMethodException e) {
32 | // TODO Auto-generated catch block
33 | e.printStackTrace();
34 | } catch (InvocationTargetException e) {
35 | // TODO Auto-generated catch block
36 | e.printStackTrace();
37 | } catch (ClassNotFoundException e) {
38 | // TODO Auto-generated catch block
39 | e.printStackTrace();
40 | }
41 | return null;
42 |
43 | }
44 |
45 | /**
46 | * 反射执行类的函数(public)
47 | * @param class_name
48 | * @param method_name
49 | * @param obj
50 | * @param pareTyple
51 | * @param pareVaules
52 | * @return
53 | */
54 | public static Object invokeMethod(String class_name, String method_name, Object obj ,Class[] pareTyple, Object[] pareVaules){
55 |
56 | try {
57 | Class obj_class = Class.forName(class_name);
58 | Method method = obj_class.getMethod(method_name,pareTyple);
59 | return method.invoke(obj, pareVaules);
60 | } catch (SecurityException e) {
61 | // TODO Auto-generated catch block
62 | e.printStackTrace();
63 | } catch (IllegalArgumentException e) {
64 | // TODO Auto-generated catch block
65 | e.printStackTrace();
66 | } catch (IllegalAccessException e) {
67 | // TODO Auto-generated catch block
68 | e.printStackTrace();
69 | } catch (NoSuchMethodException e) {
70 | // TODO Auto-generated catch block
71 | e.printStackTrace();
72 | } catch (InvocationTargetException e) {
73 | // TODO Auto-generated catch block
74 | e.printStackTrace();
75 | } catch (ClassNotFoundException e) {
76 | // TODO Auto-generated catch block
77 | e.printStackTrace();
78 | }
79 | return null;
80 |
81 | }
82 |
83 | /**
84 | * 反射得到类的属性(包括私有和保护)
85 | * @param class_name
86 | * @param obj
87 | * @param filedName
88 | * @return
89 | */
90 | public static Object getFieldOjbect(String class_name,Object obj, String filedName){
91 | try {
92 | Class obj_class = Class.forName(class_name);
93 | Field field = obj_class.getDeclaredField(filedName);
94 | field.setAccessible(true);
95 | return field.get(obj);
96 | } catch (SecurityException e) {
97 | // TODO Auto-generated catch block
98 | e.printStackTrace();
99 | } catch (NoSuchFieldException e) {
100 | // TODO Auto-generated catch block
101 | e.printStackTrace();
102 | } catch (IllegalArgumentException e) {
103 | // TODO Auto-generated catch block
104 | e.printStackTrace();
105 | } catch (IllegalAccessException e) {
106 | // TODO Auto-generated catch block
107 | e.printStackTrace();
108 | } catch (ClassNotFoundException e) {
109 | // TODO Auto-generated catch block
110 | e.printStackTrace();
111 | }
112 | return null;
113 |
114 | }
115 |
116 | /**
117 | * 反射得到类的静态属性(包括私有和保护)
118 | * @param class_name
119 | * @param filedName
120 | * @return
121 | */
122 | public static Object getStaticFieldOjbect(String class_name, String filedName){
123 |
124 | try {
125 | Class obj_class = Class.forName(class_name);
126 | Field field = obj_class.getDeclaredField(filedName);
127 | field.setAccessible(true);
128 | return field.get(null);
129 | } catch (SecurityException e) {
130 | // TODO Auto-generated catch block
131 | e.printStackTrace();
132 | } catch (NoSuchFieldException e) {
133 | // TODO Auto-generated catch block
134 | e.printStackTrace();
135 | } catch (IllegalArgumentException e) {
136 | // TODO Auto-generated catch block
137 | e.printStackTrace();
138 | } catch (IllegalAccessException e) {
139 | // TODO Auto-generated catch block
140 | e.printStackTrace();
141 | } catch (ClassNotFoundException e) {
142 | // TODO Auto-generated catch block
143 | e.printStackTrace();
144 | }
145 | return null;
146 |
147 | }
148 |
149 | /**
150 | * 设置类的属性(包括私有和保护)
151 | * @param classname
152 | * @param filedName
153 | * @param obj
154 | * @param filedVaule
155 | */
156 | public static void setFieldOjbect(String classname, String filedName, Object obj, Object filedVaule){
157 | try {
158 | Class obj_class = Class.forName(classname);
159 | Field field = obj_class.getDeclaredField(filedName);
160 | field.setAccessible(true);
161 | field.set(obj, filedVaule);
162 | } catch (SecurityException e) {
163 | // TODO Auto-generated catch block
164 | e.printStackTrace();
165 | } catch (NoSuchFieldException e) {
166 | // TODO Auto-generated catch block
167 | e.printStackTrace();
168 | } catch (IllegalArgumentException e) {
169 | // TODO Auto-generated catch block
170 | e.printStackTrace();
171 | } catch (IllegalAccessException e) {
172 | // TODO Auto-generated catch block
173 | e.printStackTrace();
174 | } catch (ClassNotFoundException e) {
175 | // TODO Auto-generated catch block
176 | e.printStackTrace();
177 | }
178 | }
179 |
180 | /**
181 | * 设置类的静态属性(包括私有和保护)
182 | * @param class_name
183 | * @param filedName
184 | * @param filedVaule
185 | */
186 | public static void setStaticOjbect(String class_name, String filedName, Object filedVaule){
187 | try {
188 | Class obj_class = Class.forName(class_name);
189 | Field field = obj_class.getDeclaredField(filedName);
190 | field.setAccessible(true);
191 | field.set(null, filedVaule);
192 | } catch (SecurityException e) {
193 | // TODO Auto-generated catch block
194 | e.printStackTrace();
195 | } catch (NoSuchFieldException e) {
196 | // TODO Auto-generated catch block
197 | e.printStackTrace();
198 | } catch (IllegalArgumentException e) {
199 | // TODO Auto-generated catch block
200 | e.printStackTrace();
201 | } catch (IllegalAccessException e) {
202 | // TODO Auto-generated catch block
203 | e.printStackTrace();
204 | } catch (ClassNotFoundException e) {
205 | // TODO Auto-generated catch block
206 | e.printStackTrace();
207 | }
208 | }
209 |
210 |
211 | }
212 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dynamicloader/LoadActivity.java:
--------------------------------------------------------------------------------
1 | package com.dynamicloader;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.util.ArrayMap;
7 | import android.util.Log;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 |
11 | import java.io.File;
12 | import java.lang.ref.WeakReference;
13 | import java.lang.reflect.Array;
14 | import java.lang.reflect.Field;
15 | import java.lang.reflect.InvocationTargetException;
16 | import java.lang.reflect.Method;
17 |
18 | import dalvik.system.DexClassLoader;
19 | import dalvik.system.PathClassLoader;
20 |
21 | /**
22 | * Created by Jam on 16-8-25
23 | * Description:
24 | */
25 | public class LoadActivity extends BaseActivity {
26 | public static final String TAG = "LoadActivity";
27 |
28 | @Override
29 | protected void onCreate(@Nullable Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_load);
32 | }
33 |
34 | public void replaceLoadedApk(View v) {
35 | try {
36 | //通过替换LoadedApk中的mClassLoader来达到加载apk中的Activity
37 | String fileDir = getCacheDir().getAbsolutePath();
38 | String filePath = fileDir + File.separator + Constants.RESOURCE_APK_NAME; //源dex/jar/apk 目录
39 | DexClassLoader loader = new DexClassLoader(filePath, getDir("dex", MODE_PRIVATE).getAbsolutePath(), null, getClassLoader());
40 |
41 | Object currentActivityThread = RefInvoke.invokeStaticMethod("android.app.ActivityThread", "currentActivityThread", new Class[]{}, new Object[]{});
42 | String packageName = getPackageName();
43 |
44 | //通过反射获取ActivityThread的 mPackages 对象
45 | ArrayMap mPackages = (ArrayMap) RefInvoke.getFieldOjbect("android.app.ActivityThread", currentActivityThread, "mPackages");
46 | //通过反射获mPackages获得当前的LoadedApk对象
47 | WeakReference wr = (WeakReference) mPackages.get(packageName);
48 | Log.i(TAG, "wr = " + wr.get());
49 | //替换LoadedApk中的mClassLoader 为我们自己的DexClassLoader
50 | RefInvoke.setFieldOjbect("android.app.LoadedApk", "mClassLoader", wr.get(), loader);
51 | Log.i(TAG, "classloader = " + loader);
52 |
53 |
54 | startResourceActivity(filePath, loader);
55 |
56 |
57 | } catch (Exception e) {
58 | Log.i(TAG, "load apk error :" + Log.getStackTraceString(e));
59 | }
60 | }
61 |
62 | /**
63 | * 启动插件Activity
64 | * @param filePath
65 | * @param loader
66 | * @throws ClassNotFoundException
67 | * @throws NoSuchFieldException
68 | * @throws IllegalAccessException
69 | * @throws NoSuchMethodException
70 | * @throws InvocationTargetException
71 | */
72 | private void startResourceActivity(String filePath, ClassLoader loader) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
73 | //加载资源
74 | loadResources(filePath);
75 |
76 |
77 | //加载Activity ,确保这里的类名和Constants.RESOURCE_APK_NAME 中的 类名相同
78 | Class clazz = loader.loadClass("com.example.resourceloaderapk.MainActivity");
79 | //找到R.layout.activity_main
80 | Class rClazz = loader.loadClass("com.example.resourceloaderapk.R$layout");
81 | Field field = rClazz.getField("activity_main");
82 | Integer ojb = (Integer)field.get(null);
83 |
84 | View view = LayoutInflater.from(this).inflate(ojb, null);
85 | //设置静态变量。这里为什么要设置静态变量呢。
86 | // 因为测试发现setContentView() 没有起作用。
87 | // 所以在启动Activity之前保存一个静态的View,设置到Activity中
88 |
89 | Method method = clazz.getMethod("setLayoutView", View.class);
90 | method.invoke(null, view);
91 |
92 | //找到MainActivity,然后启动
93 | startActivity(new Intent(this, clazz));
94 | }
95 |
96 | public void injectDexElements(View v){
97 | Log.i(TAG,"this classloader = " + getClassLoader());
98 | PathClassLoader pathClassLoader = (PathClassLoader) getClassLoader();
99 | String fileDir = getCacheDir().getAbsolutePath();
100 | String filePath = fileDir + File.separator + Constants.RESOURCE_APK_NAME; //源dex/jar/apk 目录
101 | DexClassLoader loader = new DexClassLoader(filePath, getDir("dex", MODE_PRIVATE).getAbsolutePath(), null, getClassLoader());
102 | try {
103 | //把PathClassLoader和DexClassLoader的pathList对象中的 dexElements 合并
104 | Object dexElements = combineArray(
105 | getDexElements(getPathList(pathClassLoader)),
106 | getDexElements(getPathList(loader)));
107 | //把合并后的dexElements设置到PathClassLoader的 pathList对象中的 dexElements
108 | Object pathList = getPathList(pathClassLoader);
109 | setField(pathList, pathList.getClass(), "dexElements", dexElements);
110 |
111 | startResourceActivity(filePath,pathClassLoader);
112 |
113 | } catch (IllegalArgumentException e) {
114 | e.printStackTrace();
115 | } catch (NoSuchFieldException e) {
116 | e.printStackTrace();
117 | } catch (IllegalAccessException e) {
118 | e.printStackTrace();
119 | } catch (ClassNotFoundException e) {
120 | e.printStackTrace();
121 | } catch (NoSuchMethodException e) {
122 | e.printStackTrace();
123 | } catch (InvocationTargetException e) {
124 | e.printStackTrace();
125 | }
126 | }
127 | private static Object getPathList(Object baseDexClassLoader)
128 | throws IllegalArgumentException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException {
129 | ClassLoader bc = (ClassLoader)baseDexClassLoader;
130 | return getField(baseDexClassLoader, Class.forName("dalvik.system.BaseDexClassLoader"), "pathList");
131 | }
132 |
133 | private static Object getField(Object obj, Class> cl, String field)
134 | throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
135 | Field localField = cl.getDeclaredField(field);
136 | localField.setAccessible(true);
137 | return localField.get(obj);
138 | }
139 |
140 | private static Object getDexElements(Object paramObject)
141 | throws IllegalArgumentException, NoSuchFieldException, IllegalAccessException {
142 | return getField(paramObject, paramObject.getClass(), "dexElements");
143 | }
144 | private static void setField(Object obj, Class> cl, String field,
145 | Object value) throws NoSuchFieldException,
146 | IllegalArgumentException, IllegalAccessException {
147 |
148 | Field localField = cl.getDeclaredField(field);
149 | localField.setAccessible(true);
150 | localField.set(obj, value);
151 | }
152 |
153 | private static Object combineArray(Object arrayLhs, Object arrayRhs) {
154 | Class> localClass = arrayLhs.getClass().getComponentType();
155 | int i = Array.getLength(arrayLhs);
156 | int j = i + Array.getLength(arrayRhs);
157 | Object result = Array.newInstance(localClass, j);
158 | for (int k = 0; k < j; ++k) {
159 | if (k < i) {
160 | Array.set(result, k, Array.get(arrayLhs, k));
161 | } else {
162 | Array.set(result, k, Array.get(arrayRhs, k - i));
163 | }
164 | }
165 | return result;
166 | }
167 |
168 | }
169 |
--------------------------------------------------------------------------------