Skip to content

Commit

Permalink
feat(core.gradle-plugin): 自动创建Flavor,并只在plugin上应用Transform
Browse files Browse the repository at this point in the history
在正常可安装运行的app工程上apply plugin: 'com.tencent.shadow.plugin'后,
不影响原工程正常安装运行。插件自动创建一个Flavor Dimension:Shadow,并创建两个Flavor:
normal和plugin。同时只在plugin上应用ShadowTransform。

这样不再需要将插件工程先重构为Android Library,再新建两个壳工程分别对应正常安装的app和插件了。

同时,删除了multidex相关自动化测试。因其稳定且后续大概率无相关修改。
  • Loading branch information
shifujun committed Nov 18, 2021
1 parent f80ece3 commit e38755e
Show file tree
Hide file tree
Showing 243 changed files with 454 additions and 1,041 deletions.
2 changes: 1 addition & 1 deletion projects/sample/source/sample-host/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def generateAssets(generateAssetsTask, buildType) {

def pluginZip = file("${getRootProject().getBuildDir()}/plugin-${buildType}.zip")
generateAssetsTask.dependsOn createCopyTask(
':sample-plugin-app',
':sample-app',
buildType,
'plugin-zip',
"plugin-${buildType}.zip",
Expand Down
38 changes: 0 additions & 38 deletions projects/sample/source/sample-plugin/sample-app-lib/build.gradle

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
apply from: "../sample-normal-app/build.gradle"

android {
defaultConfig {
applicationId project.SAMPLE_HOST_APP_APPLICATION_ID
}
}

dependencies {
//Shadow Transform后业务代码会有一部分实际引用runtime中的类
//如果不以compileOnly方式依赖,会导致其他Transform或者Proguard找不到这些类
compileOnly 'com.tencent.shadow.core:runtime'
}

buildscript {
repositories {
if (!System.getenv().containsKey("DISABLE_TENCENT_MAVEN_MIRROR")) {
Expand All @@ -30,34 +16,88 @@ buildscript {
}
}

apply plugin: 'com.android.application'
apply plugin: 'com.tencent.shadow.plugin'

android {
compileSdkVersion project.COMPILE_SDK_VERSION

defaultConfig {
applicationId 'com.tencent.shadow.sample.plugin.app'
minSdkVersion project.MIN_SDK_VERSION
targetSdkVersion project.TARGET_SDK_VERSION
versionCode project.VERSION_CODE
versionName project.VERSION_NAME
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

signingConfig signingConfigs.create("release")
signingConfig.initWith(buildTypes.debug.signingConfig)
}
}

// 将插件applicationId设置为和宿主相同
productFlavors {
plugin {
applicationId project.SAMPLE_HOST_APP_APPLICATION_ID
}
}

lintOptions {
abortOnError false
}
}

dependencies {
implementation project(":slidingmenu")
implementation project(":pinnedheaderexpandablelistview")
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'

//注意sample-host-lib要用compileOnly编译而不打包在插件中。在packagePlugin任务中配置hostWhiteList允许插件访问宿主的类。
pluginCompileOnly project(":sample-host-lib")
normalImplementation project(":sample-host-lib")


//Shadow Transform后业务代码会有一部分实际引用runtime中的类
//如果不以compileOnly方式依赖,会导致其他Transform或者Proguard找不到这些类
pluginCompileOnly 'com.tencent.shadow.core:runtime'
}

preBuild.dependsOn(":sample-host-lib:jarDebugPackage")


def createDuplicateApkTask(buildType) {
def apkDir = file("${getBuildDir()}/outputs/apk/$buildType")
def apkDir = file("${getBuildDir()}/outputs/apk/plugin/$buildType")

return tasks.create("duplicate${buildType.capitalize()}ApkTask", Copy) {
return tasks.create("duplicatePlugin${buildType.capitalize()}ApkTask", Copy) {
group = 'build'
description = "复制一个sample-plugin-app-${buildType}.apk用于测试目的"
description = "复制一个sample-app-plugin-${buildType}.apk用于测试目的"
from(apkDir) {
include("sample-plugin-app-${buildType}.apk")
rename { "sample-plugin-app-${buildType}2.apk" }
include("sample-app-plugin-${buildType}.apk")
rename { "sample-app-plugin-${buildType}2.apk" }
}
into(apkDir)

}.dependsOn(":sample-plugin-app:assemble${buildType.capitalize()}")
}.dependsOn(":sample-app:assemblePlugin${buildType.capitalize()}")
}

tasks.whenTaskAdded { task ->
if (task.name == "assembleDebug") {
if (task.name == "assemblePluginDebug") {
def createTask = createDuplicateApkTask('debug')
task.finalizedBy(createTask)
}
if (task.name == "assembleRelease") {
if (task.name == "assemblePluginRelease") {
def createTask = createDuplicateApkTask('release')
task.finalizedBy(createTask)
}
}

apply plugin: 'com.tencent.shadow.plugin'


shadow {
transform {
Expand All @@ -73,17 +113,17 @@ shadow {
pluginApk1 {
businessName = 'sample-plugin-app'
partKey = 'sample-plugin-app'
buildTask = ':sample-plugin-app:assembleDebug'
apkName = 'sample-plugin-app-debug.apk'
apkPath = 'projects/sample/source/sample-plugin/sample-plugin-app/build/outputs/apk/debug/sample-plugin-app-debug.apk'
buildTask = ':sample-app:assemblePluginDebug'
apkName = 'sample-app-plugin-debug.apk'
apkPath = 'projects/sample/source/sample-plugin/sample-app/build/outputs/apk/plugin/debug/sample-app-plugin-debug.apk'
hostWhiteList = ["com.tencent.shadow.sample.host.lib"]
}
pluginApk2 {
businessName = 'sample-plugin-app2'
partKey = 'sample-plugin-app2'
buildTask = ':sample-plugin-app:assembleDebug'
apkName = 'sample-plugin-app-debug2.apk'
apkPath = 'projects/sample/source/sample-plugin/sample-plugin-app/build/outputs/apk/debug/sample-plugin-app-debug2.apk'
buildTask = ':sample-app:assemblePluginDebug'
apkName = 'sample-app-plugin-debug2.apk'
apkPath = 'projects/sample/source/sample-plugin/sample-app/build/outputs/apk/plugin/debug/sample-app-plugin-debug2.apk'
hostWhiteList = ["com.tencent.shadow.sample.host.lib"]
}
}
Expand All @@ -96,17 +136,17 @@ shadow {
pluginApk1 {
businessName = 'sample-plugin-app'
partKey = 'sample-plugin-app'
buildTask = ':sample-plugin-app:assembleRelease'
buildTask = ':sample-app:assemblePluginRelease'
apkName = 'sample-plugin-app-release.apk'
apkPath = 'projects/sample/source/sample-plugin/sample-plugin-app/build/outputs/apk/release/sample-plugin-app-release.apk'
apkPath = 'projects/sample/source/sample-plugin/sample-app/build/outputs/apk/plugin/release/sample-app-plugin-release.apk'
hostWhiteList = ["com.tencent.shadow.sample.host.lib"]
}
pluginApk2 {
businessName = 'sample-plugin-app2'
partKey = 'sample-plugin-app2'
buildTask = ':sample-plugin-app:assembleRelease'
buildTask = ':sample-app:assemblePluginRelease'
apkName = 'sample-plugin-app-release2.apk'
apkPath = 'projects/sample/source/sample-plugin/sample-plugin-app/build/outputs/apk/release/sample-plugin-app-release2.apk'
apkPath = 'projects/sample/source/sample-plugin/sample-app/build/outputs/apk/plugin/release/sample-app-plugin-release2.apk'
hostWhiteList = ["com.tencent.shadow.sample.host.lib"]
}
}
Expand All @@ -124,4 +164,4 @@ shadow {
compactVersion = [1, 2, 3]
uuidNickName = "1.1.5"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@
<activity android:name=".usecases.fragment.TestDialogFragmentActivity" />

<provider
android:authorities="com.tencent.shadow.provider.test"
android:authorities="${applicationId}.provider.test"
android:name="com.tencent.shadow.sample.plugin.app.lib.usecases.provider.TestProvider" />

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.tencent.shadow.test.plugin.general_cases.fileprovider"
android:authorities="${applicationId}.general_cases.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

package com.tencent.shadow.sample.plugin.app.lib.gallery.util;

import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;

final public class UiUtil {
@SuppressLint("SetTextI18n")
public static ViewGroup makeItemView(Context viewContext, String labelText, String viewTag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.tencent.shadow.sample.plugin.app.lib.R;
import com.tencent.shadow.sample.plugin.app.lib.gallery.cases.entity.UseCase;
import com.tencent.shadow.sample.plugin.app.lib.gallery.util.ToastUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

package com.tencent.shadow.sample.plugin.app.lib.usecases.context;

import static android.os.Environment.DIRECTORY_MUSIC;
import static android.os.Environment.DIRECTORY_PODCASTS;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
Expand All @@ -42,9 +45,6 @@
import java.util.LinkedList;
import java.util.List;

import static android.os.Environment.DIRECTORY_MUSIC;
import static android.os.Environment.DIRECTORY_PODCASTS;

abstract class SubDirContextThemeWrapperTestActivity extends BaseActivity {

private LinearLayout mRootView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import android.view.ViewTreeObserver;
import android.widget.ImageView;

import com.tencent.shadow.sample.plugin.app.lib.BuildConfig;
import com.tencent.shadow.sample.plugin.app.lib.R;
import com.tencent.shadow.sample.plugin.app.lib.gallery.cases.entity.UseCase;

Expand Down Expand Up @@ -91,7 +92,7 @@ public void onClick(View v) {
Uri contentUri;
if (targetSdkVersion() >= Build.VERSION_CODES.N) {
contentUri = FileProvider.getUriForFile(TestFileProviderActivity.this,
"com.tencent.shadow.test.plugin.general_cases.fileprovider", mFile);
BuildConfig.APPLICATION_ID + ".general_cases.fileprovider", mFile);
// contentUri = Uri.parse("content://com.tencent.shadow.contentprovider.authority/com.tencent.shadow.test.plugin.general_cases.lib.gallery.fileprovider" +
// "/name/data/data/com.tencent.shadow.test.hostapp/files/images/1548417832706.jpg");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
import android.net.Uri;
import android.provider.BaseColumns;

import com.tencent.shadow.sample.plugin.app.lib.BuildConfig;


public class TestProviderInfo {

protected static final String CONTENT_AUTHORITY = "com.tencent.shadow.provider.test";
protected static final String CONTENT_AUTHORITY = BuildConfig.APPLICATION_ID + ".provider.test";
protected static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);

protected static final String PATH_TEST = "test";

public static final class TestEntry implements BaseColumns {

public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_TEST).build();
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit e38755e

Please sign in to comment.