Skip to content

Commit

Permalink
Merge branch 'Tencent#8' into 'master'
Browse files Browse the repository at this point in the history
从Shadow中移除Multidex源码

fix Tencent#8 

修改如下:
1. 从Shadow中移除Multidex源码
1. 将Demo-plugin改造为分Dex的apk
1. 使ShadowContext get到的ApplicationInfo中sourceDir指向插件的apk

测试中Multidex日志如下:
```
I/MultiDex: VM with version 1.6.0 does not have multidex support
I/MultiDex: Installing application
I/MultiDex: MultiDexExtractor.load(/data/data/com.tencent.shadow.demo_host/files/ShadowPluginManager/UnpackedPlugin/dynamic_demo/3e85789d91dd7d3c5504a7c0e27bdaad/plugin-debug.zip/demo-plugin-debug.apk, false, )
I/MultiDex: Blocking on lock /data/data/com.tencent.shadow.demo_host/code_cache/secondary-dexes/MultiDex.lock
I/MultiDex: /data/data/com.tencent.shadow.demo_host/code_cache/secondary-dexes/MultiDex.lock locked
I/MultiDex: Detected that extraction must be performed.
I/MultiDex: Extraction is needed for file /data/data/com.tencent.shadow.demo_host/code_cache/secondary-dexes/demo-plugin-debug.apk.classes2.zip
I/MultiDex: Extracting /data/data/com.tencent.shadow.demo_host/code_cache/secondary-dexes/tmp-demo-plugin-debug.apk.classes1505316161.zip
I/MultiDex: Renaming to /data/data/com.tencent.shadow.demo_host/code_cache/secondary-dexes/demo-plugin-debug.apk.classes2.zip
I/MultiDex: Extraction succeeded - length /data/data/com.tencent.shadow.demo_host/code_cache/secondary-dexes/demo-plugin-debug.apk.classes2.zip: 610363 - crc: 234747838
I/MultiDex: load found 1 secondary dex files
I/MultiDex: install done
```

可以看到Multidex使用data目录存储其余Dex,另外还会用宿主的SharePreference。这些东西可能会在插件升级时冲突。

待验证的问题:
- [x] 插件直接使用宿主的Data目录是否会导致插件升级时Multidex认为已经处理过而出错。
- [x] demo-main使用的Multidex版本是1.0.2,应该至少再验证一下最新版本,或者现网业务。

See merge request !69
  • Loading branch information
shifujun committed May 5, 2019
2 parents 45126bd + 7693733 commit 9089e34
Show file tree
Hide file tree
Showing 53 changed files with 383 additions and 1,143 deletions.
45 changes: 31 additions & 14 deletions projects/demo/host-apk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,41 @@ def createCopyTask(projectName, buildType, name, apkName, inputFile, taskName) {
}.dependsOn("${projectName}:${taskName}")
}

def generateAssets(generateAssetsTask, buildType) {

def moduleName = 'pluginmanager-apk'
def pluginManagerApkFile = file(
"${project(":projects:demo:pluginmanager-apk").getBuildDir()}" +
"/outputs/apk/${buildType}/" +
"${moduleName}-${buildType}.apk"
)
generateAssetsTask.dependsOn createCopyTask(
':projects:demo:pluginmanager-apk',
buildType,
moduleName,
'pluginmanager.apk',
pluginManagerApkFile,
"assemble${buildType.capitalize()}"
)

def demoPluginZip = file("${getRootProject().getBuildDir()}/plugin-${buildType}.zip")
generateAssetsTask.dependsOn createCopyTask(
':projects:demo:plugin-app:demo-plugin',
buildType,
'plugin-zip',
"plugin-${buildType}.zip",
demoPluginZip,
"package${buildType.capitalize()}Plugin"
)


}

tasks.whenTaskAdded { task ->
if (task.name == "generateDebugAssets") {
def buildType = 'debug'
def moduleName = 'pluginmanager-apk'
def inputFile = file("${project(":projects:demo:pluginmanager-apk").getBuildDir()}/outputs/apk/${buildType}/${moduleName}-${buildType}.apk")
task.dependsOn createCopyTask(':projects:demo:pluginmanager-apk', buildType, moduleName, 'pluginmanager.apk', inputFile, 'assembleDebug')

def zipFile =file("${getRootProject().getBuildDir()}/plugin-debug.zip")
task.dependsOn createCopyTask(':projects:demo:plugin-app:demo-plugin', buildType, 'plugin-zip', 'plugin-debug.zip', zipFile, 'packageDebugPlugin')
generateAssets(task, 'debug')
}
if (task.name == "generateReleaseAssets") {
def buildType = 'release'
def moduleName = 'pluginmanager-apk'
def inputFile = file("${project(":projects:demo:pluginmanager-apk").getBuildDir()}/outputs/apk/${buildType}/${moduleName}-${buildType}.apk")
task.dependsOn createCopyTask(':projects:demo:pluginmanager-apk', buildType, moduleName, 'pluginmanager.apk', inputFile, 'assembleRelease')

def zipFile =file("${getRootProject().getBuildDir()}/plugin-release.zip")
task.dependsOn createCopyTask(':projects:demo:plugin-app:demo-plugin', buildType, 'plugin-zip', 'plugin-release.zip', zipFile, 'packageReleasePlugin')
generateAssets(task, 'release')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import androidx.test.core.app.ApplicationProvider;

public class ActivityContextSubDirTest extends SubDirContextThemeWrapperTest {
public class ActivityContextSubDirTest extends DemoBaseTest {
@Override
Intent getLaunchIntent() {
Intent pluginIntent = new Intent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

@RunWith(AndroidJUnit4.class)
@LargeTest
public class ActivityWindowSoftModeTest extends BaseTest {
public class ActivityWindowSoftModeTest extends DemoBaseTest {

@Override
Intent getLaunchIntent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,16 @@
import android.content.Intent;

import androidx.test.core.app.ApplicationProvider;
import androidx.test.espresso.Espresso;
import androidx.test.espresso.action.ViewActions;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;

import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;


@RunWith(AndroidJUnit4.class)
@LargeTest
public class ApplicationTest extends BaseTest {
public class ApplicationTest extends DemoBaseTest {

@Override
Intent getLaunchIntent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public abstract class BaseTest {
*/
abstract Intent getLaunchIntent();

/**
* 要启动的插件的PartKey
*/
abstract String getPartKey();

/**
* 检测view
* @param tag view的tag
Expand All @@ -34,7 +39,7 @@ public void matchTextWithViewTag(String tag,String text){
public void launchActivity() {
SimpleIdlingResource idlingResource = HostApplication.getApp().mIdlingResource;
IdlingRegistry.getInstance().register(idlingResource);
PluginActivityScenario.launch(getLaunchIntent());
PluginActivityScenario.launch(getPartKey(), getLaunchIntent());

Espresso.onView(ViewMatchers.withId(R.id.jump)).perform(ViewActions.click());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

@RunWith(AndroidJUnit4.class)
@LargeTest
public class BasicTest extends BaseTest {
public class BasicTest extends DemoBaseTest {

@Override
Intent getLaunchIntent() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.tencent.shadow.demo.host;

import com.tencent.shadow.demo.testutil.Constant;

abstract class DemoBaseTest extends BaseTest {
@Override
String getPartKey() {
return Constant.PART_KEY_DEMO_MAIN;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.hamcrest.Matchers;
import org.junit.Test;

public class GetCallingActivityTest extends BaseTest {
public class GetCallingActivityTest extends DemoBaseTest {

@Override
Intent getLaunchIntent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import androidx.test.espresso.matcher.ViewMatchers;

import com.tencent.shadow.demo.interfaces.HostTestInterface;
import com.tencent.shadow.demo.other.HostOtherInterface;

import org.hamcrest.Matchers;
import org.junit.Test;

public class HostInterfaceTest extends BaseTest {
public class HostInterfaceTest extends DemoBaseTest {

@Override
Intent getLaunchIntent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import com.tencent.shadow.demo.testutil.Constant;

final class PluginActivityScenario {
static ActivityScenario<JumpToPluginActivity> launch(Intent pluginIntent) {
static ActivityScenario<JumpToPluginActivity> launch(String partKey, Intent pluginIntent) {
Intent intent = new Intent(ApplicationProvider.getApplicationContext(), JumpToPluginActivity.class);
intent.putExtra(Constant.KEY_PLUGIN_PART_KEY, partKey);
intent.putExtra(Constant.KEY_ACTIVITY_CLASSNAME, pluginIntent.getComponent().getClassName());
intent.putExtra(Constant.KEY_EXTRAS, pluginIntent.getExtras());
return ActivityScenario.launch(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

@RunWith(AndroidJUnit4.class)
@LargeTest
public class PluginServiceTest extends BaseTest {
public class PluginServiceTest extends DemoBaseTest {

@Override
Intent getLaunchIntent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static android.os.Environment.DIRECTORY_MUSIC;
import static android.os.Environment.DIRECTORY_PODCASTS;

abstract class SubDirContextThemeWrapperTest extends BaseTest {
abstract class SubDirContextThemeWrapperTest extends DemoBaseTest {

private static final String PREFIX = "ShadowPlugin";
private static final String BUSINESS_NAME = "demo";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public void jump(View view) {

Bundle bundle = new Bundle();
bundle.putString(Constant.KEY_PLUGIN_ZIP_PATH, PluginHelper.getInstance().pluginZipFile.getAbsolutePath());
bundle.putString(Constant.KEY_PLUGIN_PART_KEY, getIntent().getStringExtra(Constant.KEY_PLUGIN_PART_KEY));
bundle.putString(Constant.KEY_ACTIVITY_CLASSNAME, getIntent().getStringExtra(Constant.KEY_ACTIVITY_CLASSNAME));
bundle.putBundle(Constant.KEY_EXTRAS, getIntent().getBundleExtra(Constant.KEY_EXTRAS));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

import com.tencent.shadow.demo.testutil.Constant;

import test.TestViewConstructorCacheView;


public class MainActivity extends Activity {
Expand All @@ -15,7 +24,52 @@ public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.TestHostTheme);
setContentView(R.layout.activity_main);

LinearLayout rootView = new LinearLayout(this);
rootView.setOrientation(LinearLayout.VERTICAL);

TextView infoTextView = new TextView(this);
infoTextView.setText(R.string.main_activity_info);
rootView.addView(infoTextView);

final Spinner partKeySpinner = new Spinner(this);
ArrayAdapter<String> partKeysAdapter = new ArrayAdapter<>(this, R.layout.part_key_adapter);
partKeysAdapter.addAll(
Constant.PART_KEY_DEMO_MAIN,
Constant.PART_KEY_MULTIDEX_V1_0_2,
Constant.PART_KEY_MULTIDEX_V2_0_1
);
partKeySpinner.setAdapter(partKeysAdapter);

rootView.addView(partKeySpinner);

Button startPluginButton = new Button(this);
startPluginButton.setText(R.string.start_plugin);
startPluginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String partKey = (String) partKeySpinner.getSelectedItem();
Intent intent = new Intent(MainActivity.this, PluginLoadActivity.class);
intent.putExtra(Constant.KEY_PLUGIN_PART_KEY, partKey);
switch (partKey) {
case Constant.PART_KEY_DEMO_MAIN:
intent.putExtra(Constant.KEY_ACTIVITY_CLASSNAME, "com.tencent.shadow.demo.gallery.splash.SplashActivity");
break;
case Constant.PART_KEY_MULTIDEX_V1_0_2:
intent.putExtra(Constant.KEY_ACTIVITY_CLASSNAME, "com.tencent.shadow.demo.plugin.multidex.v1_0_2.PluginMultidexV1_0_2Activity");
break;
case Constant.PART_KEY_MULTIDEX_V2_0_1:
intent.putExtra(Constant.KEY_ACTIVITY_CLASSNAME, "com.tencent.shadow.demo.plugin.multidex.v2_0_1.PluginMultidexV2_0_1Activity");
break;
}
startActivity(intent);
}
});
rootView.addView(startPluginButton);

rootView.addView(new TestViewConstructorCacheView(this));

setContentView(rootView);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
Expand All @@ -39,12 +93,4 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
}
}


public void startDemoPlugin(View view) {

startActivity(new Intent(this, PluginLoadActivity.class));

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ public void run() {

Bundle bundle = new Bundle();
bundle.putString(Constant.KEY_PLUGIN_ZIP_PATH, PluginHelper.getInstance().pluginZipFile.getAbsolutePath());
bundle.putString(Constant.KEY_PLUGIN_PART_KEY, getIntent().getStringExtra(Constant.KEY_PLUGIN_PART_KEY));
bundle.putString(Constant.KEY_ACTIVITY_CLASSNAME, getIntent().getStringExtra(Constant.KEY_ACTIVITY_CLASSNAME));

HostApplication.getApp().getPluginManager()
.enter(PluginLoadActivity.this, Constant.FROM_ID_ENTRY_START_DEMO_PLUGIN, bundle, new EnterCallback() {
.enter(PluginLoadActivity.this, Constant.FROM_ID_START_ACTIVITY, bundle, new EnterCallback() {
@Override
public void onShowLoadingView(final View view) {
mHandler.post(new Runnable() {
Expand Down
32 changes: 0 additions & 32 deletions projects/demo/host-apk/src/main/res/layout/activity_main.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black" />
12 changes: 12 additions & 0 deletions projects/demo/host-apk/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="main_activity_info">
这是一个全动态的demo,插件管理(dynamic-pluginmanager-apk),
插件框架(dynamic-loader-apk及dynamic-runtime-apk),
以及插件本身(demo-plugin),都是动态加载的
</string>

<string name="start_plugin">
启动插件
</string>
</resources>
1 change: 1 addition & 0 deletions projects/demo/loader-apk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
implementation 'com.tencent.shadow.core:loader'
implementation 'com.tencent.shadow.dynamic:dynamic-loader'
implementation 'com.tencent.shadow.dynamic:dynamic-loader-impl'
implementation project(':projects:demo:test-util')

compileOnly 'com.tencent.shadow.core:runtime-debug'
compileOnly 'com.tencent.shadow.core:common-debug'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.tencent.shadow.core.loader.infos.ContainerProviderInfo;
import com.tencent.shadow.core.loader.managers.ComponentManager;
import com.tencent.shadow.demo.testutil.Constant;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -54,8 +55,14 @@ public ContainerProviderInfo onBindContainerContentProvider(ComponentName plugin
@Override
public List<BroadcastInfo> getBroadcastInfoList(String partKey) {
List<ComponentManager.BroadcastInfo> broadcastInfos = new ArrayList<>();
broadcastInfos.add(new ComponentManager.BroadcastInfo("com.tencent.shadow.demo.usecases.receiver.MyReceiver",
new String[]{"com.tencent.test.action"}));
if (partKey.equals(Constant.PART_KEY_DEMO_MAIN)) {
broadcastInfos.add(
new ComponentManager.BroadcastInfo(
"com.tencent.shadow.demo.usecases.receiver.MyReceiver",
new String[]{"com.tencent.test.action"}
)
);
}
return broadcastInfos;
}

Expand Down
Loading

0 comments on commit 9089e34

Please sign in to comment.