Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #380

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Dev #380

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

import com.didi.virtualapk.PluginManager;

import java.util.ArrayList;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

/**
Expand Down Expand Up @@ -79,9 +81,14 @@ public void markIntentIfNeeded(Intent intent) {
String targetClassName = intent.getComponent().getClassName();
// search map and return specific launchmode stub activity
if (!targetPackageName.equals(mContext.getPackageName()) && mPluginManager.getLoadedPlugin(targetPackageName) != null) {
intent.putExtra(Constants.KEY_IS_PLUGIN, true);
intent.putExtra(Constants.KEY_TARGET_PACKAGE, targetPackageName);
intent.putExtra(Constants.KEY_TARGET_ACTIVITY, targetClassName);
// mark plugin by categories
Set<String> categories = intent.getCategories();
if (categories != null) {
intent.putStringArrayListExtra(Constants.KEY_CATEGORY, new ArrayList<>(categories));
categories.clear();
}
intent.addCategory(Constants.CATEGORY_PREFIX_TARGET_PACKAGE + targetPackageName);
intent.addCategory(Constants.CATEGORY_PREFIX_TARGET_ACTIVITY + targetClassName);
dispatchStubActivity(intent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
* Created by renyugang on 16/8/15.
*/
public class Constants {
public static final String KEY_IS_PLUGIN = "isPlugin";
public static final String KEY_TARGET_PACKAGE = "target.package";
public static final String KEY_TARGET_ACTIVITY = "target.activity";
public static final String KEY_CATEGORY = "va.intent.extra.category";
public static final String CATEGORY_PREFIX = "va.intent.category.";
public static final String CATEGORY_PREFIX_TARGET_PACKAGE = CATEGORY_PREFIX + "package.";
public static final String CATEGORY_PREFIX_TARGET_ACTIVITY = CATEGORY_PREFIX + "activity.";

// public static final String KEY_IS_PLUGIN = "isPlugin";
// public static final String KEY_TARGET_PACKAGE = "target.package";
// public static final String KEY_TARGET_ACTIVITY = "target.activity";

public static final String OPTIMIZE_DIR = "dex";
public static final String NATIVE_DIR = "valibs";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ protected void injectActivity(Activity activity) {
ComponentName component = PluginUtil.getComponent(intent);
Intent wrapperIntent = new Intent(intent);
wrapperIntent.setClassName(component.getPackageName(), component.getClassName());
wrapperIntent.setExtrasClassLoader(activity.getClassLoader());
activity.setIntent(wrapperIntent);

} catch (Exception e) {
Expand All @@ -200,7 +201,7 @@ public boolean handleMessage(Message msg) {
try {
Reflector reflector = Reflector.with(r);
Intent intent = reflector.field("intent").get();
intent.setExtrasClassLoader(mPluginManager.getHostContext().getClassLoader());
// intent.setExtrasClassLoader(mPluginManager.getHostContext().getClassLoader());
ActivityInfo activityInfo = reflector.field("activityInfo").get();

if (PluginUtil.isIntentFromPlugin(intent)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,37 @@ public static ComponentName getComponent(Intent intent) {
return null;
}
if (isIntentFromPlugin(intent)) {
return new ComponentName(intent.getStringExtra(Constants.KEY_TARGET_PACKAGE),
intent.getStringExtra(Constants.KEY_TARGET_ACTIVITY));
String pkg = null;
String activity = null;
for (String cat : intent.getCategories()) {
if (cat.startsWith(Constants.CATEGORY_PREFIX_TARGET_PACKAGE)) {
pkg = cat.substring(Constants.CATEGORY_PREFIX_TARGET_PACKAGE.length());
continue;
}

if (cat.startsWith(Constants.CATEGORY_PREFIX_TARGET_ACTIVITY)) {
activity = cat.substring(Constants.CATEGORY_PREFIX_TARGET_ACTIVITY.length());
continue;
}
}
return new ComponentName(pkg, activity);
}

return intent.getComponent();
}

public static boolean isIntentFromPlugin(Intent intent) {
if (intent == null) {
if (intent == null || intent.getCategories() == null) {
return false;
}
return intent.getBooleanExtra(Constants.KEY_IS_PLUGIN, false);

for (String cat : intent.getCategories()) {
if (cat.startsWith(Constants.CATEGORY_PREFIX)) {
return true;
}
}

return false;
}

public static int getTheme(Context context, Intent intent) {
Expand Down
2 changes: 1 addition & 1 deletion CoreLibrary/upload.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def gitUrl = 'https://github.com/didi/VirtualAPK' // Git仓库的url
group = GROUP_ID
archivesBaseName = 'core'

version = "0.9.7.1"
version = "0.9.9.1-dev"


install {
Expand Down
2 changes: 1 addition & 1 deletion PluginDemo/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ dependencies {
// the following aars are also compiled in host project, so they will be filterd when build plugin apk.
// but, wo can still visit their Class and Resources.
implementation 'com.android.support:appcompat-v7:23.4.0'
implementation 'com.didi.virtualapk:core:0.9.6'
implementation 'com.didi.virtualapk:0.9.9.1-dev'
}

apply plugin: 'com.didi.virtualapk.plugin'
Expand Down
2 changes: 1 addition & 1 deletion PluginDemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.didi.virtualapk:gradle:0.9.8.5.1-dev'
classpath 'com.didi.virtualapk:gradle:0.9.8.6.2-dev'
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies {
testImplementation 'junit:junit:4.12'

implementation 'com.android.support:appcompat-v7:23.4.0'
implementation 'com.didi.virtualapk:core:0.9.7-dev'
implementation 'com.didi.virtualapk:core:0.9.9.1-dev'
// implementation project (':CoreLibrary')

}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.didi.virtualapk:gradle:0.9.8.5.1-dev'
classpath 'com.didi.virtualapk:gradle:0.9.8.6.2-dev'

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
Expand Down
2 changes: 1 addition & 1 deletion virtualapk-gradle-plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
GROUP_ID=com.didi.virtualapk
ARTIFACT_ID=gradle
VERSION=0.9.8.5.1-dev
VERSION=0.9.8.6.2-dev
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.android.build.gradle.internal.TaskManager
import com.android.build.gradle.internal.api.ApplicationVariantImpl
import com.android.build.gradle.internal.variant.VariantFactory
import com.android.builder.core.VariantType
import com.didi.virtualapk.os.Build
import com.didi.virtualapk.tasks.AssemblePlugin
import com.didi.virtualapk.utils.Log
import com.didi.virtualapk.utils.Reflect
Expand Down Expand Up @@ -43,14 +44,8 @@ public abstract class BasePlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
this.project = project
project.ext.set(Constants.GRADLE_3_1_0, false)

try {
Class.forName('com.android.builder.core.VariantConfiguration')
} catch (Throwable e) {
// com.android.tools.build:gradle:3.1.0
project.ext.set(Constants.GRADLE_3_1_0, true)
}
Build.initGradleVersion(project)

AppPlugin appPlugin = project.plugins.findPlugin(AppPlugin)

Expand All @@ -76,7 +71,7 @@ public abstract class BasePlugin implements Plugin<Project> {

project.extensions.create('virtualApk', VAExtention)

if (project.extensions.extraProperties.get(Constants.GRADLE_3_1_0)) {
if (Build.isSupportVersion(project, Build.VERSION_CODE.V3_1_X)) {
TaskManager taskManager = Reflect.on(appPlugin).field('taskManager').get()
taskFactory = taskManager.getTaskFactory()
} else {
Expand Down Expand Up @@ -105,7 +100,7 @@ public abstract class BasePlugin implements Plugin<Project> {
}
}

if (project.extensions.extraProperties.get(Constants.GRADLE_3_1_0)) {
if (Build.isSupportVersion(project, Build.VERSION_CODE.V3_1_X)) {
taskFactory.configure("assemblePlugin", action)
} else {
taskFactory.named("assemblePlugin", action)
Expand Down Expand Up @@ -141,7 +136,7 @@ public abstract class BasePlugin implements Plugin<Project> {

appPlugin.variantManager.productFlavors.each {
String variantName
if (project.extensions.extraProperties.get(Constants.GRADLE_3_1_0)) {
if (Build.isSupportVersion(project, Build.VERSION_CODE.V3_1_X)) {
variantName = Reflect.on('com.android.build.gradle.internal.core.VariantConfiguration')
.call('computeFullName', it.key, buildType, VariantType.DEFAULT, null)
.get()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.android.build.gradle.internal.pipeline.TransformTask
import com.android.build.gradle.internal.publishing.AndroidArtifacts
import com.android.build.gradle.internal.transforms.ProGuardTransform
import com.android.build.gradle.tasks.ProcessAndroidResources
import com.didi.virtualapk.os.Build
import com.didi.virtualapk.utils.FileUtil
import com.didi.virtualapk.utils.Log
import com.didi.virtualapk.utils.Reflect
Expand Down Expand Up @@ -34,19 +35,13 @@ public class VAHostPlugin implements Plugin<Project> {
public void apply(Project project) {

this.project = project
project.ext.set(Constants.GRADLE_3_1_0, false)

try {
Class.forName('com.android.builder.core.VariantConfiguration')
} catch (Throwable e) {
// com.android.tools.build:gradle:3.1.0
project.ext.set(Constants.GRADLE_3_1_0, true)
}

Build.initGradleVersion(project)

//The target project must be a android application module
if (!project.plugins.hasPlugin('com.android.application')) {
Log.e(TAG, "application required!")
return;
return
}

vaHostDir = new File(project.getBuildDir(), "VAHost")
Expand Down Expand Up @@ -97,7 +92,7 @@ public class VAHostPlugin implements Plugin<Project> {
List<String> deps = new ArrayList<String>()
Log.i TAG, "Used compileClasspath: ${applicationVariant.name}"
Set<ArtifactDependencyGraph.HashableResolvedArtifactResult> compileArtifacts
if (project.extensions.extraProperties.get(Constants.GRADLE_3_1_0)) {
if (Build.isSupportVersion(project, Build.VERSION_CODE.V3_1_X)) {
ImmutableMap<String, String> buildMapping = Reflect.on('com.android.build.gradle.internal.ide.ModelBuilder')
.call('computeBuildMapping', project.gradle)
.get()
Expand Down Expand Up @@ -168,7 +163,7 @@ public class VAHostPlugin implements Plugin<Project> {
/**
* Keep the host app resource id same with last publish, in order to compatible with the published plugin
*/
def keepResourceIds(variant) {
def keepResourceIds(variant) {


def VIRTUAL_APK_DIR = new File([project.rootDir, 'virtualapk'].join(File.separator))
Expand Down Expand Up @@ -211,7 +206,7 @@ public class VAHostPlugin implements Plugin<Project> {
project.configurations.compile.resolvedConfiguration.resolvedArtifacts.each {
if (it.extension == 'aar') {
def moduleVersion = it.moduleVersion.id
def resPath = new File(aarDir,"${moduleVersion.group}/${moduleVersion.name}/${moduleVersion.version}/res")
def resPath = new File(aarDir, "${moduleVersion.group}/${moduleVersion.name}/${moduleVersion.version}/res")
collectAarResourceEntries(moduleVersion.version, resPath.path, mergeXml, typeEntries)
}
}
Expand Down Expand Up @@ -244,9 +239,9 @@ public class VAHostPlugin implements Plugin<Project> {
def name = it.@name
if (type.endsWith('-array')) {
type = 'array'
} else if (type == 'item'){
} else if (type == 'item') {
type = it.@type
} else if (type == 'declare-styleable'){
} else if (type == 'declare-styleable') {
return
}
def entrySet = getEntriesSet(type, typeEntries)
Expand Down Expand Up @@ -280,20 +275,20 @@ public class VAHostPlugin implements Plugin<Project> {
}
if (type == 'style') {
if (styleNameMap.containsKey(values[2])) {
pw.println "\t<public type=\"${type}\" name=\"${styleNameMap.get(values[2])}\" id=\"${values[3]}\" />"
pw.println "\t<public type=\"${type}\" name=\"${styleNameMap.get(values[2])}\" id=\"${values[3]}\"/>"
}
return
}
//ID does not filter and remains redundant
if (type == 'id') {
pw.println "\t<public type=\"${type}\" name=\"${values[2]}\" id=\"${values[3]}\" />"
pw.println "\t<public type=\"${type}\" name=\"${values[2]}\" id=\"${values[3]}\"/>"
return
}

//Only keep resources' Id that are present in the current project
Set entries = hostResourceEntries[type]
if (entries != null && entries.contains(values[2])) {
pw.println "\t<public type=\"${type}\" name=\"${values[2]}\" id=\"${values[3]}\" />"
pw.println "\t<public type=\"${type}\" name=\"${values[2]}\" id=\"${values[3]}\"/>"
} else {
if (entries == null) {
if (type != lastSplitType) {
Expand All @@ -302,7 +297,7 @@ public class VAHostPlugin implements Plugin<Project> {
}

} else {
if (type != 'attr'){
if (type != 'attr') {
println ">>>> ${type} : ${values[2]} is deleted"
}

Expand All @@ -328,7 +323,7 @@ public class VAHostPlugin implements Plugin<Project> {
}


def Set<String> getEntriesSet (final String type, final Map typeEntries) {
def Set<String> getEntriesSet(final String type, final Map typeEntries) {
def entries = typeEntries[type]
if (entries == null) {
entries = [] as Set<String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ public class Aapt {
void filterResources(final List<?> retainedTypes, final Set<String> outFilteredResources) {
def resDir = new File(assetDir, 'res')
resDir.listFiles().each { typeDir ->
def type = retainedTypes.find { typeDir.name.startsWith(it.name) }
def type = retainedTypes.find {
if (typeDir.name.startsWith("animator")) {
it.name == "animator"
} else {
typeDir.name.startsWith(it.name)
}
}
if (type == null) {
typeDir.listFiles().each {
outFilteredResources.add("res/$typeDir.name/$it.name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ public class ArscEditor extends AssetEditor {
private static def LIBRARY_CHUNK_SIZE = 272 // ResTable_lib_header & ResTable_lib_entry
private static def TABLE_SIZE_POS = 4

private int mTableConfigSize = 52 // sizeof(ResTable_config)

ArscEditor(File file, def v) {
super(file, v)
if (version != null && version.major >= 24) {
mTableConfigSize = 56
}
}

/**
Expand Down Expand Up @@ -661,11 +657,13 @@ public class ArscEditor extends AssetEditor {
// c.screenConfig2.screenLayout2 = readByte()
// c.screenConfig2.screenConfigPad1 = readByte()
// c.screenConfig2.screenConfigPad2 = readShort()
c.ignored = readBytes(mTableConfigSize)
c.size = readInt()
c.ignored = readBytes(c.size - 4)
return c
}
/** Write struct ResTable_config */
def writeTableConfig(c) {
writeInt(c.size)
writeBytes(c.ignored)
}

Expand All @@ -682,7 +680,8 @@ public class ArscEditor extends AssetEditor {
skip(4) // id(1), res0(1), res1(2)
type.entryCount= readInt()
type.entriesStart = readInt()
skip(mTableConfigSize) // ResTable_type.config: struct ResTable_config
def size = readInt()
skip(size - 4) // ResTable_type.config: struct ResTable_config
}
return type
}
Expand Down
Loading