Skip to content

Commit

Permalink
1、适配AndroidX
Browse files Browse the repository at this point in the history
2、gradle升级到3.5.4
3、64位适配
4、优化部分崩溃问题
  • Loading branch information
raotao committed Mar 24, 2022
1 parent f24b44e commit e44e8b0
Show file tree
Hide file tree
Showing 105 changed files with 1,189 additions and 562 deletions.
8 changes: 3 additions & 5 deletions replugin-host-gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ apply plugin: 'maven-publish'
repositories {
jcenter()
mavenCentral()
maven() { url 'https://maven.google.com' }
google()
}

buildscript {
repositories {
jcenter()
mavenCentral()
google()
}

dependencies {
Expand All @@ -38,10 +39,7 @@ buildscript {
}

dependencies {
compile 'com.android.tools.build:gradle:2.1.3' // >= 2.14.1
// compile 'com.android.tools.build:gradle:2.3.3' // gradle 3.3 <= {} < gradle-4.10
// compile 'com.android.tools.build:gradle:3.3.2' // >= gradle-4.10
// compile 'com.android.tools.build:gradle:3.4.1' // >= gradle-5.1.1
compile 'com.android.tools.build:gradle:3.5.4'
compile 'org.json:json:20160212'
compile 'org.codehaus.groovy:groovy:2.4.7'
compile 'com.squareup:javapoet:1.5.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public class Replugin implements Plugin<Project> {
/**
*
* @hyongbai
*
*
* 在gradle plugin 3.0.0之前,file是文件,且文件名为AndroidManifest.xml
* 在gradle plugin 3.0.0之后,file是目录,(特别是3.3.2)在这里改成递归的方式替换内部所有的 manifest 文件
*
Expand Down Expand Up @@ -203,6 +203,8 @@ public class Replugin implements Plugin<Project> {
println '--------------------------------------------------------------------------'
// println "${TAG} appID=${appID}"
println "${TAG} useAppCompat=${config.useAppCompat}"

println "${TAG} useAndroidX=${config.useAndroidX}"
// println "${TAG} persistentName=${config.persistentName}"
println "${TAG} countProcess=${config.countProcess}"

Expand Down Expand Up @@ -286,4 +288,7 @@ class RepluginConfig {

/** 当发现插件目录下面有不合法的插件 jar (有可能是特殊定制 jar)时是否停止构建,默认是 true */
def enablePluginFileIllegalStopBuild = true

/** 宿主是否支持了 Androidx 库 */
def useAndroidX = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public class RePluginHostConfig {
// 是否使用 AppCompat 库
public static boolean ACTIVITY_PIT_USE_APPCOMPAT = ${config.useAppCompat};
// HOST 是否使用 androidx 库
public static boolean HOST_USE_ANDROIDX = ${config.useAndroidX};
//------------------------------------------------------------
// 主程序支持的插件版本范围
//------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion replugin-host-library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ buildscript {
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.android.tools.build:gradle:3.5.4'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
Expand All @@ -32,6 +33,7 @@ allprojects {
repositories {
jcenter()
mavenCentral()
google()
}
}

Expand Down
2 changes: 1 addition & 1 deletion replugin-host-library/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
8 changes: 2 additions & 6 deletions replugin-host-library/replugin-host-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 9
Expand All @@ -43,10 +43,6 @@ android {

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')

// 以“占位符”(Provided)的方式来引用support-v4,不会编入AAR
// 但宿主需要支持Support-v4(至少应支持LocalBroadcastManager)
provided 'com.android.support:support-v4:25.2.0'
}

project.ext.RP_ARTIFACT_ID = 'replugin-host-lib'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,26 @@ interface IPluginManagerServer {
* @return 正在运行此插件的进程名列表。一定不会为Null
*/
String[] getRunningProcessesByPlugin(String pluginName);

/**
* 预安装内置插件到app_p_a目录,只做p.l文件的写入,真正的安装执行,在做插件Load的时候执行
*
* @param 待安装的插件列表
* @return 安装后的所有插件列表
*/
List<PluginInfo> preInstallBuiltins(in List<PluginInfo> pluginInfos);

void updateTP(String plugin,int type,String path);

/**
* 设置isUsed状态,并通知所有进程更新
*
* @param pluginName 插件名
* @param path 是否已经使用
* @param type 是否已经使用
* @param used 是否已经使用
*/
void updateUsedNew(String pluginName, String path, int type, boolean used);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.qihoo360.loader.utils;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import com.qihoo360.replugin.utils.ReflectUtils;

public class LocalBroadcastManager {

private static String V4_MANAGER = "android.support.v4.content.LocalBroadcastManager";
private static String ANDROIDX_MANAGER = "androidx.localbroadcastmanager.content.LocalBroadcastManager";
private static LocalBroadcastManager instance;

private Context context;
private boolean init;
private static Object managerObj;

public static LocalBroadcastManager getInstance(Context context) {
if (instance == null) {
synchronized (LocalBroadcastManager.class) {
if (instance == null) {
instance = new LocalBroadcastManager(context);
}
}
}
return instance;
}

private LocalBroadcastManager(Context context) {
this.context = context.getApplicationContext();
loadClass();
}

private void loadClass() {
try {
Class cls = null;
try {
cls = ReflectUtils.getClass(ANDROIDX_MANAGER);
} catch (Exception e) {
cls = ReflectUtils.getClass(V4_MANAGER);
}
if (cls == null) {
return;
}
managerObj = ReflectUtils.getMethod(cls, "getInstance", new Class<?>[]{Context.class}).invoke(null, context);
init = true;
} catch (Exception e) {
}
}

public boolean registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
if (!init || managerObj == null) {
return false;
}
try {
ReflectUtils.getMethod(managerObj.getClass(), "registerReceiver",
BroadcastReceiver.class, IntentFilter.class).invoke(managerObj, receiver, filter);
return true;
} catch (Exception e) {
}
return false;
}

public boolean unregisterReceiver(BroadcastReceiver receiver) {
if (!init || managerObj == null) {
return false;
}
try {
ReflectUtils.getMethod(managerObj.getClass(), "unregisterReceiver",
BroadcastReceiver.class).invoke(managerObj, receiver);
return true;
} catch (Exception e) {
}
return false;
}

public boolean sendBroadcast(Intent intent) {
if (!init || managerObj == null) {
return false;
}
try {
ReflectUtils.getMethod(managerObj.getClass(), "sendBroadcast",
Intent.class).invoke(managerObj, intent);
return true;
} catch (Exception e) {
}
return false;
}

public boolean sendBroadcastSync(Intent intent) {
if (!init || managerObj == null) {
return false;
}
try {
ReflectUtils.getMethod(managerObj.getClass(), "sendBroadcastSync",
Intent.class).invoke(managerObj, intent);
return true;
} catch (Exception e) {
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,29 +196,6 @@ final void addNormal(PluginInfo info) {
static final void builder(Context context, PxAll all) {
// 搜索所有本地插件和V5插件
Finder.search(context, all);

// 删除不适配的PLUGINs
for (PluginInfo p : all.getOthers()) {
// TODO 如果已存在built-in和V5则不删除
if (LOG) {
LogDebug.d(PLUGIN_TAG, "delete obsolote plugin=" + p);
}
boolean rc = p.deleteObsolote(context);
if (!rc) {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "can't delete obsolote plugin=" + p);
}
}
}

// 删除所有和PLUGINs不一致的DEX文件
deleteUnknownDexs(context, all);

// 删除所有和PLUGINs不一致的SO库目录
// Added by Jiongxuan Zhang
deleteUnknownLibs(context, all);

// 构建数据
}

private static File getDexDir(Context context) {
Expand Down Expand Up @@ -286,7 +263,7 @@ private static void deleteUnknownDexs(Context context, PxAll all) {
private static void deleteUnknownLibs(Context context, PxAll all) {
HashSet<String> names = new HashSet<>();
for (PluginInfo p : all.getPlugins()) {
names.add(p.getNativeLibsDir().getName());
names.add(p.getOldNativeLibsDir().getName());
}

File dir = context.getDir(Constant.LOCAL_PLUGIN_DATA_LIB_DIR, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,8 @@ public class Finder {
* 扫描插件
*/
static final void search(Context context, PxAll all) {
// 扫描内置插件
// 扫描内置插件-builtin
FinderBuiltin.loadPlugins(context, all);

// 扫描V5插件
File pluginDir = context.getDir(Constant.LOCAL_PLUGIN_SUB_DIR, 0);
V5Finder.search(context, pluginDir, all);

// 扫描现有插件,包括刚才从V5插件文件更新过来的文件
HashSet<File> deleted = new HashSet<File>();
{
if (LOG) {
LogDebug.d(PLUGIN_TAG, "search plugins: dir=" + pluginDir.getAbsolutePath());
}
searchLocalPlugins(pluginDir, all, deleted);
}

// 删除非插件文件和坏的文件
for (File f : deleted) {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "search: delete plugin dir invalid file=" + f.getAbsolutePath());
}
boolean rc = f.delete();
if (!rc) {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "search: can't delete plugin dir invalid file=" + f.getAbsolutePath());
}
}
}
deleted.clear();
}

private static final void searchLocalPlugins(File dir, PxAll all, HashSet<File> others) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.qihoo360.replugin.utils.Charsets;
import com.qihoo360.replugin.utils.CloseableUtils;
Expand All @@ -37,6 +38,7 @@

import static com.qihoo360.replugin.helper.LogDebug.LOG;
import static com.qihoo360.replugin.helper.LogDebug.PLUGIN_TAG;
import static com.qihoo360.replugin.helper.LogDebug.TAG_NO_PN;

/**
* @author RePlugin Team
Expand Down Expand Up @@ -89,6 +91,9 @@ private static final void readConfig(InputStream in, PxAll all) throws IOExcepti
if (LOG) {
LogDebug.d(PLUGIN_TAG, "built-in plugins config: item: " + info);
}
if (LOG) {
Log.d(TAG_NO_PN, "add builtin plugin=" + info);
}
all.addBuiltin(info);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import static com.qihoo360.replugin.helper.LogDebug.LOADER_TAG;
import static com.qihoo360.replugin.helper.LogDebug.LOG;
import static com.qihoo360.replugin.helper.LogDebug.PLUGIN_TAG;
import static com.qihoo360.replugin.helper.LogDebug.TAG_NO_PN;
import static com.qihoo360.replugin.helper.LogRelease.LOGR;

/**
Expand Down Expand Up @@ -452,6 +453,7 @@ final boolean invoke(PluginCommImpl manager) {
}

final boolean loadEntryMethod2() {
long start = System.currentTimeMillis();
//
try {
String className = Factory.PLUGIN_ENTRY_PACKAGE_PREFIX + "." + mPluginName + "." + Factory.PLUGIN_ENTRY_CLASS_NAME;
Expand All @@ -466,6 +468,9 @@ final boolean loadEntryMethod2() {
// LogRelease.e(PLUGIN_TAG, e.getMessage(), e);
// }
}
if (LOG) {
Log.d(TAG_NO_PN, "load loadEntryMethod2 for " + mPluginName + " time=" + (System.currentTimeMillis() - start));
}
return mCreateMethod2 != null;
}

Expand All @@ -488,6 +493,8 @@ final boolean loadEntryMethod3() {

final boolean invoke2(PluginCommImpl x) {
try {

long start = System.currentTimeMillis();
IBinder manager = null; // TODO
IBinder b = (IBinder) mCreateMethod2.invoke(null, mPkgContext, getClass().getClassLoader(), manager);
if (b == null) {
Expand Down
Loading

0 comments on commit e44e8b0

Please sign in to comment.