diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 044afe6..18fa7cb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -18,6 +18,11 @@ + + + \ No newline at end of file diff --git a/app/src/main/java/com/plugin/component/MainActivity.java b/app/src/main/java/com/plugin/component/MainActivity.java index c95f020..e1e385f 100644 --- a/app/src/main/java/com/plugin/component/MainActivity.java +++ b/app/src/main/java/com/plugin/component/MainActivity.java @@ -1,5 +1,6 @@ package com.plugin.component; +import android.content.Intent; import android.os.Bundle; import com.google.android.material.floatingactionbutton.FloatingActionButton; @@ -10,6 +11,8 @@ import com.plugin.library.ISdk; import com.plugin.library.ISdk2; import com.plugin.librarykotlin.IGetFromLibrary; import com.plugin.librarykotlin.IProvideFromKotlin; +import com.plugin.librarykotlin.JavaParcelable; +import com.plugin.librarykotlin.KotlinParcelable; import com.plugin.module.R; import com.plugin.pin.MainBase; import com.plugin.pin.base.PBase; @@ -56,6 +59,18 @@ public class MainActivity extends AppCompatActivity { stringBuilder.append("common -> " + new PCommon().getString() + "\n"); stringBuilder.append("普通模块测试 -> " + new LibraryWithoutPlugin().getString() + "\n"); ((TextView) findViewById(R.id.text)).setText(stringBuilder); + findViewById(R.id.text).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + JavaParcelable javaParcelable = new JavaParcelable(); + KotlinParcelable kotlinParcelable = new KotlinParcelable(); + Intent intent = new Intent(MainActivity.this, ParcelableActivity.class); + intent.putExtra("javaParcelable",javaParcelable); + intent.putExtra("kotlinParcelable",kotlinParcelable); + startActivity(intent); + } + }); + } public void initComponent() { diff --git a/app/src/main/java/com/plugin/component/ParcelableActivity.java b/app/src/main/java/com/plugin/component/ParcelableActivity.java new file mode 100644 index 0000000..2f10f1d --- /dev/null +++ b/app/src/main/java/com/plugin/component/ParcelableActivity.java @@ -0,0 +1,33 @@ +package com.plugin.component; + +import android.content.Intent; +import android.os.Bundle; +import android.widget.TextView; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import com.plugin.librarykotlin.JavaParcelable; +import com.plugin.librarykotlin.KotlinParcelable; +import com.plugin.module.R; + +public class ParcelableActivity extends AppCompatActivity { + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_parcelable); + + JavaParcelable javaParcelable = getIntent().getParcelableExtra("javaParcelable"); + KotlinParcelable kotlinParcelable = getIntent().getParcelableExtra("kotlinParcelable"); + TextView textView = this.findViewById(R.id.text); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("javaParcelable ->" + "\n"); + stringBuilder.append("int : " + javaParcelable.i + "\n"); + stringBuilder.append("string : " + javaParcelable.string + "\n"); + stringBuilder.append("kotlinParcelable ->" + "\n"); + stringBuilder.append("int : " + kotlinParcelable.getInt() + "\n"); + stringBuilder.append("string : " + kotlinParcelable.getString() + "\n"); + textView.setText(stringBuilder.toString()); + } +} diff --git a/app/src/main/res/layout/activity_parcelable.xml b/app/src/main/res/layout/activity_parcelable.xml new file mode 100644 index 0000000..9fb6fb5 --- /dev/null +++ b/app/src/main/res/layout/activity_parcelable.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 58eda22..9cf5733 100644 --- a/build.gradle +++ b/build.gradle @@ -11,13 +11,14 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:3.1.0' - classpath "com.effective.plugins:component:$component_version" +// classpath "com.effective.plugins:component:$component_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" //调试需要 -// classpath "com.effective.plugins:component-plugin" + classpath "com.effective.plugins:component-plugin" //发布需要 classpath 'com.novoda:bintray-release:0.9.1' + classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" } } diff --git a/component-plugin/src/main/groovy/com/plugin/component/FlatDirModuleComponentSelector.groovy b/component-plugin/src/main/groovy/com/plugin/component/FlatDirModuleComponentSelector.groovy new file mode 100644 index 0000000..c08d4f9 --- /dev/null +++ b/component-plugin/src/main/groovy/com/plugin/component/FlatDirModuleComponentSelector.groovy @@ -0,0 +1,125 @@ +package com.plugin.component + +import org.gradle.api.artifacts.ModuleIdentifier +import org.gradle.api.artifacts.VersionConstraint +import org.gradle.api.artifacts.component.ComponentIdentifier +import org.gradle.api.artifacts.component.ModuleComponentIdentifier +import org.gradle.api.artifacts.component.ModuleComponentSelector +import org.gradle.api.attributes.AttributeContainer +import org.gradle.api.capabilities.Capability +import org.gradle.api.internal.artifacts.DefaultModuleIdentifier +import org.gradle.api.internal.artifacts.ImmutableVersionConstraint +import org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint +import org.gradle.api.internal.attributes.ImmutableAttributes +import org.gradle.internal.component.external.model.DefaultModuleComponentSelector + +public class FlatDirModuleComponentSelector implements ModuleComponentSelector { + + private final ModuleIdentifier moduleIdentifier + private final ImmutableVersionConstraint versionConstraint + private final ImmutableAttributes attributes + private final List requestedCapabilities + private final int hashCode + + private FlatDirModuleComponentSelector(ModuleIdentifier module, ImmutableVersionConstraint version, ImmutableAttributes attributes, List requestedCapabilities) { + assert module != null: "module cannot be null" + + assert version != null: "version cannot be null" + + assert attributes != null: "attributes cannot be null" + + assert requestedCapabilities != null: "capabilities cannot be null" + + this.moduleIdentifier = module + this.versionConstraint = version + this.attributes = attributes + this.requestedCapabilities = requestedCapabilities + this.hashCode = Objects.hash(version, module, attributes, requestedCapabilities) + } + + public String getDisplayName() { + String group = this.moduleIdentifier.getGroup() + String module = this.moduleIdentifier.getName() + String version = this.getVersion() + StringBuilder builder = new StringBuilder(group.length() + module.length() + this.versionConstraint.getRequiredVersion().length() + 2) + builder.append(group) + builder.append(":") + builder.append(module) + if (version.length() > 0) { + builder.append(":") + builder.append(version) + } + + if (this.versionConstraint.getBranch() != null) { + builder.append(" (branch: ") + builder.append(this.versionConstraint.getBranch()) + builder.append(")") + } + + return builder.toString() + } + + public String getGroup() { + return this.moduleIdentifier.getGroup() + } + + public String getModule() { + return this.moduleIdentifier.getName() + } + + public String getVersion() { + return this.versionConstraint.getRequiredVersion().isEmpty() ? this.versionConstraint.getPreferredVersion() : this.versionConstraint.getRequiredVersion() + } + + public VersionConstraint getVersionConstraint() { + return this.versionConstraint + } + + public ModuleIdentifier getModuleIdentifier() { + return this.moduleIdentifier + } + + public AttributeContainer getAttributes() { + return this.attributes + } + + List getRequestedCapabilities() { + return this.requestedCapabilities + } + + public boolean matchesStrictly(ComponentIdentifier identifier) { + assert identifier != null: "identifier cannot be null" + + if (identifier instanceof ModuleComponentIdentifier) { + ModuleComponentIdentifier moduleComponentIdentifier = (ModuleComponentIdentifier) identifier + if (this.moduleIdentifier.getGroup() == moduleComponentIdentifier.getGroup() + && this.moduleIdentifier.getName() == moduleComponentIdentifier.getModule()) { + return true + } + } + return false + } + + public boolean equals(Object o) { + if (o != null && o instanceof DefaultModuleComponentSelector) { + DefaultModuleComponentSelector selector = (DefaultModuleComponentSelector) o + if (this.moduleIdentifier.getName() == selector.moduleIdentifier.getName() && + this.moduleIdentifier.getGroup() == selector.moduleIdentifier.getGroup()) { + return true + } + } + return false + } + + public int hashCode() { + return this.hashCode + } + + public String toString() { + return this.getDisplayName() + } + + public static ModuleComponentSelector newSelector(String name) { + return new FlatDirModuleComponentSelector(DefaultModuleIdentifier.newId("", name), DefaultImmutableVersionConstraint.of(), ImmutableAttributes.EMPTY, new ArrayList()) + } +} \ No newline at end of file diff --git a/gradleScript/component.gradle b/gradleScript/component.gradle index 410640d..4d82c62 100644 --- a/gradleScript/component.gradle +++ b/gradleScript/component.gradle @@ -40,6 +40,7 @@ component { dependencies { implementation 'com.google.code.gson:gson:2.8.1' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" } } } @@ -64,7 +65,7 @@ component { targetModuleName 'debugModule' //申明调试模块运行时链接组件的资源,表明运行 debugModule 时使用目录资源 -// targetDebugName 'libraryWithoutPlugin' + targetDebugName 'library' configuration { diff --git a/libraryKotlin/build.gradle b/libraryKotlin/build.gradle index 5e4c1d8..d13623a 100644 --- a/libraryKotlin/build.gradle +++ b/libraryKotlin/build.gradle @@ -18,6 +18,10 @@ android { versionCode 1 versionName "1.0" } + + androidExtensions { + experimental = true + } } dependencies { diff --git a/libraryKotlin/src/main/sdk/com/plugin/librarykotlin/JavaParcelable.java b/libraryKotlin/src/main/sdk/com/plugin/librarykotlin/JavaParcelable.java new file mode 100644 index 0000000..b5ba32d --- /dev/null +++ b/libraryKotlin/src/main/sdk/com/plugin/librarykotlin/JavaParcelable.java @@ -0,0 +1,42 @@ +package com.plugin.librarykotlin; + +import android.os.Parcel; +import android.os.Parcelable; + +public class JavaParcelable implements Parcelable { + + public int i = 0; + public String string = "JavaParcelable"; + + public JavaParcelable() { + + } + + public JavaParcelable(Parcel source) { + this.i = source.readInt(); + this.string = source.readString(); + } + + public static final Creator CREATOR = new Creator() { + @Override + public JavaParcelable createFromParcel(Parcel source) { + return new JavaParcelable(source); + } + + @Override + public JavaParcelable[] newArray(int size) { + return new JavaParcelable[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(i); + dest.writeString(string); + } +} diff --git a/libraryKotlin/src/main/sdk/com/plugin/librarykotlin/KotlinParcelable.kt b/libraryKotlin/src/main/sdk/com/plugin/librarykotlin/KotlinParcelable.kt new file mode 100644 index 0000000..d79b7e7 --- /dev/null +++ b/libraryKotlin/src/main/sdk/com/plugin/librarykotlin/KotlinParcelable.kt @@ -0,0 +1,41 @@ +package com.plugin.librarykotlin + +import android.os.Parcel +import android.os.Parcelable + +class KotlinParcelable : Parcelable { + + var int: Int = 0 + + var string: String = "KotlinParcelable" + + constructor() + + constructor(source: Parcel) { + source.writeInt(int) + source.writeString(string) + } + + companion object{ + + @JvmField + val CREATOR: Parcelable.Creator = object : Parcelable.Creator { + override fun createFromParcel(source: Parcel): KotlinParcelable { + return KotlinParcelable(source) + } + + override fun newArray(size: Int): Array { + return Array(size) {KotlinParcelable()} + } + } + } + + override fun describeContents(): Int { + return 0 + } + + override fun writeToParcel(dest: Parcel?, flags: Int) { + dest?.writeInt(int) + dest?.writeString(string) + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 368fd20..a1bd157 100644 --- a/settings.gradle +++ b/settings.gradle @@ -5,8 +5,8 @@ //include ':component-plugin' //调试插件 -//includeBuild './component-plugin' -// +includeBuild './component-plugin' + include ':app', ':pins' include ':debugModule' include ':library', ':libraryKotlin', ':libraryWithoutPlugin'