From b712b2bce5ffcebab9e22c9f57096bef15926ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=BD=A6=E6=98=8E?= Date: Thu, 28 May 2020 20:55:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E6=A1=86=E6=9E=B61.0.8?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E5=8D=87=E7=A8=B3=E5=AE=9A=E6=80=A7=EF=BC=8C?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=9E=81=E7=AB=AF=E5=9C=BA=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-zh.md | 4 +++- README.md | 4 +++- .../com/plugin/component/MainActivity.java | 1 + build.gradle | 2 +- component-core/build.gradle | 18 +++++++-------- .../com/plugin/component/ComponentInfo.kt | 5 ++++- .../com/plugin/component/ComponentManager.kt | 8 +++++++ component-plugin/build.gradle | 22 +++++++++---------- component-plugin/gradlew | 0 .../com/plugin/component/Constants.groovy | 2 +- .../transform/InjectCodeAdapter.groovy | 2 +- gradle.properties | 8 +++---- .../java/com/plugin/library/Component.java | 12 +++++----- .../plugin/librarykotlin/KotlinComponent.kt | 6 +++++ local.properties | 4 ++-- settings.gradle | 2 +- 16 files changed, 61 insertions(+), 39 deletions(-) mode change 100644 => 100755 component-plugin/gradlew diff --git a/README-zh.md b/README-zh.md index ef6e1ee..c937577 100644 --- a/README-zh.md +++ b/README-zh.md @@ -19,6 +19,8 @@ README: [English](https://github.com/YummyLau/ComponentPlugin/blob/master/README * 提供更人性化的调试日志格式 * 2019/12/09 * 优化插件 gradle 增量编译 +* 2020/05/28 + * 调整sdk注入逻辑,优化 sdk 注册,避免极端情况下多模块重复注册导致已绑定的实现丢失 ### 为什么要使用 @@ -82,7 +84,7 @@ buildscript { jcenter() } dependencies { - classpath "com.effective.plugins:component:1.0.6 + classpath "com.effective.plugins:component:1.0.8 } } allprojects { diff --git a/README.md b/README.md index 7d661bc..c7e3f18 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ From the very beginning, I learned that "WeChat's Modular Architecture Reconstru      * Provide a more user-friendly debug log format * 2019/12/09 * Optimization plugin gradle incremental compilation +* 2020/05/28 +     * Adjust the sdk injection logic, optimize the sdk registration, to avoid the repeated registration of multiple modules in extreme cases, resulting in the loss of the bound implementation ### Why use it @@ -81,7 +83,7 @@ buildscript { jcenter() } dependencies { - classpath "com.effective.plugins:component:1.0.6 + classpath "com.effective.plugins:component:1.0.8 } } allprojects { diff --git a/app/src/main/java/com/plugin/component/MainActivity.java b/app/src/main/java/com/plugin/component/MainActivity.java index e1e385f..ce0e23b 100644 --- a/app/src/main/java/com/plugin/component/MainActivity.java +++ b/app/src/main/java/com/plugin/component/MainActivity.java @@ -22,6 +22,7 @@ import com.plugin.pin.home.PHome; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; +import android.util.Log; import android.view.View; import android.view.Menu; import android.view.MenuItem; diff --git a/build.gradle b/build.gradle index b978208..fea2025 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ apply from: "./gradleScript/config.gradle" buildscript { ext.kotlin_version = '1.3.50' - ext.component_version = '1.0.6' + ext.component_version = '1.0.8' repositories { google() diff --git a/component-core/build.gradle b/component-core/build.gradle index 99041ea..5ee436f 100644 --- a/component-core/build.gradle +++ b/component-core/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' -//apply plugin: 'com.novoda.bintray-release' +apply plugin: 'com.novoda.bintray-release' android { compileSdkVersion 29 @@ -29,12 +29,12 @@ dependencies { } -//publish { -// userOrg = 'yummylau' -// groupId = 'com.effective.android' -// artifactId = 'component-core' -// publishVersion = '1.0.4' -// desc = 'Android component core code' -// website = 'https://github.com/YummyLau/ComponentPlugin' -//} +publish { + userOrg = 'yummylau' + groupId = 'com.effective.android' + artifactId = 'component-core' + publishVersion = '1.0.5' + desc = 'Android component core code' + website = 'https://github.com/YummyLau/ComponentPlugin' +} diff --git a/component-core/src/main/java/com/plugin/component/ComponentInfo.kt b/component-core/src/main/java/com/plugin/component/ComponentInfo.kt index a89a3b7..3286f5c 100644 --- a/component-core/src/main/java/com/plugin/component/ComponentInfo.kt +++ b/component-core/src/main/java/com/plugin/component/ComponentInfo.kt @@ -2,6 +2,7 @@ package com.plugin.component import android.app.Application import android.util.ArrayMap +import android.util.Log /** * 运行时完成收集 @@ -40,7 +41,9 @@ class ComponentInfo { fun registerSdk(sdkClass: Class<*>, sdkImpl: Any) { - sdkMap[sdkClass] = sdkImpl + if(!isSdkReady(sdkClass) || sdkImpl!is Class<*>){ + sdkMap[sdkClass] = sdkImpl + } } fun unregisterSdk(sdkKey: Class<*>): Boolean { diff --git a/component-core/src/main/java/com/plugin/component/ComponentManager.kt b/component-core/src/main/java/com/plugin/component/ComponentManager.kt index eafff15..635b598 100644 --- a/component-core/src/main/java/com/plugin/component/ComponentManager.kt +++ b/component-core/src/main/java/com/plugin/component/ComponentManager.kt @@ -31,6 +31,14 @@ object ComponentManager { ComponentManager.application = application sComponentInfoArrayMap = ArrayMap() sInit = true + injectComponentWithSdk(application) + } + + /** + * 仅仅用于 asm 注入 + */ + private fun injectComponentWithSdk(application: Application){ + } private fun checkInit() { diff --git a/component-plugin/build.gradle b/component-plugin/build.gradle index bfe0e67..d6a5f7c 100644 --- a/component-plugin/build.gradle +++ b/component-plugin/build.gradle @@ -1,10 +1,10 @@ apply plugin: 'groovy' apply plugin: 'maven' -//apply plugin: 'com.novoda.bintray-release' +apply plugin: 'com.novoda.bintray-release' group = 'com.effective.plugins' archivesBaseName = 'component' -version = '1.0.6' +version = '1.0.8' //设置本地发布路径 uploadArchives { @@ -20,7 +20,7 @@ dependencies { implementation gradleApi() implementation localGroovy() implementation 'com.android.tools.build:gradle:3.1.0' - implementation 'org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.50' + implementation 'org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.70' implementation 'org.ow2.asm:asm:7.1' implementation 'org.ow2.asm:asm-commons:7.1' implementation 'org.ow2.asm:asm-util:7.1' @@ -43,13 +43,13 @@ repositories { } -//publish { -// userOrg = 'yummylau' -// groupId = 'com.effective.plugins' -// artifactId = 'component' -// publishVersion = '1.0.6' -// desc = 'Android component plugin' -// website = 'https://github.com/YummyLau/ComponentPlugin' -//} +publish { + userOrg = 'yummylau' + groupId = 'com.effective.plugins' + artifactId = 'component' + publishVersion = '1.0.8' + desc = 'Android component plugin' + website = 'https://github.com/YummyLau/ComponentPlugin' +} diff --git a/component-plugin/gradlew b/component-plugin/gradlew old mode 100644 new mode 100755 diff --git a/component-plugin/src/main/groovy/com/plugin/component/Constants.groovy b/component-plugin/src/main/groovy/com/plugin/component/Constants.groovy index 7c50670..d1e0a9f 100644 --- a/component-plugin/src/main/groovy/com/plugin/component/Constants.groovy +++ b/component-plugin/src/main/groovy/com/plugin/component/Constants.groovy @@ -44,7 +44,7 @@ class Constants { public static String IMPL_PRE = 'impl-' public static String COMPONENT_PRE = 'component-' public static String DEBUG_COMPONENT_PRE = 'component(Debug)-' - public static String CORE_DEPENDENCY = "com.effective.android:component-core:1.0.4" + public static String CORE_DEPENDENCY = "com.effective.android:component-core:1.0.5" //sourceSet - default public static String JAVA_PATH = "src/main/java" diff --git a/component-plugin/src/main/groovy/com/plugin/component/transform/InjectCodeAdapter.groovy b/component-plugin/src/main/groovy/com/plugin/component/transform/InjectCodeAdapter.groovy index 49ca7fe..fdeca52 100644 --- a/component-plugin/src/main/groovy/com/plugin/component/transform/InjectCodeAdapter.groovy +++ b/component-plugin/src/main/groovy/com/plugin/component/transform/InjectCodeAdapter.groovy @@ -73,7 +73,7 @@ class InjectCodeAdapter extends ClassVisitor { @Override protected void onMethodEnter() { injectComponentAutoInitCode = - className == sComponentManagerPath && name == "init" && descriptor == "(Landroid/app/Application;)V" + className == sComponentManagerPath && name == "injectComponentWithSdk" && descriptor == "(Landroid/app/Application;)V" } @Override diff --git a/gradle.properties b/gradle.properties index 1ee71f0..7cef99e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,9 +18,9 @@ android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true -systemProp.http.proxyHost=127.0.0.1 -systemProp.http.proxyPort=8001 -systemProp.https.proxyHost=127.0.0.1 -systemProp.https.proxyPort=8001 +#systemProp.http.proxyHost=127.0.0.1 +#systemProp.http.proxyPort=8001 +#systemProp.https.proxyHost=127.0.0.1 +#systemProp.https.proxyPort=8001 diff --git a/library/src/main/java/com/plugin/library/Component.java b/library/src/main/java/com/plugin/library/Component.java index e966823..0feff2c 100644 --- a/library/src/main/java/com/plugin/library/Component.java +++ b/library/src/main/java/com/plugin/library/Component.java @@ -14,16 +14,16 @@ public class Component implements IComponent { @Override public void attachComponent(Application application) { Log.d("component-plugin", "Component#attachComponent"); - SdkManager.register(this, ISdk.class, SdkShareImpl.class); - SdkManager.register(this, ISdk2.class, SdkShareImpl.class); - SdkManager.register(this, IProvideFromLibrary.class, ProvideFromLibraryImpl.class); +// SdkManager.register(this, ISdk.class, SdkShareImpl.class); +// SdkManager.register(this, ISdk2.class, SdkShareImpl.class); +// SdkManager.register(this, IProvideFromLibrary.class, ProvideFromLibraryImpl.class); } @Override public void detachComponent() { Log.d("component-plugin", "Component#detachComponent"); - SdkManager.unregister(ISdk.class); - SdkManager.unregister(ISdk2.class); - SdkManager.unregister(IProvideFromLibrary.class); +// SdkManager.unregister(ISdk.class); +// SdkManager.unregister(ISdk2.class); +// SdkManager.unregister(IProvideFromLibrary.class); } } diff --git a/libraryKotlin/src/main/java/com/plugin/librarykotlin/KotlinComponent.kt b/libraryKotlin/src/main/java/com/plugin/librarykotlin/KotlinComponent.kt index 4d525d8..c26514f 100644 --- a/libraryKotlin/src/main/java/com/plugin/librarykotlin/KotlinComponent.kt +++ b/libraryKotlin/src/main/java/com/plugin/librarykotlin/KotlinComponent.kt @@ -2,8 +2,13 @@ package com.plugin.librarykotlin import android.app.Application import android.util.Log +import com.plugin.component.ComponentManager import com.plugin.component.IComponent +import com.plugin.component.SdkManager +import com.plugin.component.SdkManager.getSdk import com.plugin.component.anno.AutoInjectComponent +import com.plugin.library.IProvideFromLibrary +import com.plugin.library.ISdk @AutoInjectComponent(impl = [ProvideFromKotlinImpl::class, GetFromLibraryImpl::class]) @@ -11,6 +16,7 @@ class KotlinComponent : IComponent { override fun attachComponent(application: Application) { Log.d("component-plugin", "KotlinComponent#attachComponent") + ComponentManager.init(application) } override fun detachComponent() { diff --git a/local.properties b/local.properties index f8747e4..877025a 100644 --- a/local.properties +++ b/local.properties @@ -4,5 +4,5 @@ # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. -#Sat Aug 31 17:50:10 CST 2019 -sdk.dir=/Users/yummy/Library/Android/sdk +#Thu May 28 17:59:06 CST 2020 +sdk.dir=/Users/g8931/Library/Android/sdk diff --git a/settings.gradle b/settings.gradle index a862845..e760fbd 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ //发布调试 core //include ':component-core' -// + //发布插件 //include ':component-plugin'