Skip to content

Commit ca0c820

Browse files
committed
add kotlin to demo
1 parent afc61bd commit ca0c820

File tree

6 files changed

+48
-75
lines changed

6 files changed

+48
-75
lines changed

Samples/PluginMain/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
3+
24
//A const defined in the top-level build.gradle file
35
apply from: HOST_FAIRY_SCRIPT
46

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
package com.example.pluginmain;
1+
package com.example.pluginmain
22

3-
public class MessageEvent {
4-
5-
private String message;
6-
7-
public MessageEvent(String message) {
8-
this.message = message;
9-
}
10-
11-
public String getMessage() {
12-
return message;
13-
}
14-
15-
public void setMessage(String message) {
16-
this.message = message;
17-
}
18-
}
3+
class MessageEvent(var message: String)

Samples/PluginTest/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
3+
24
//A const defined in the top-level build.gradle file
35
apply from: PLUGIN_FAIRY_SCRIPT
46

Lines changed: 39 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,39 @@
1-
package com.example.plugintest;
2-
3-
import android.app.ActivityManager;
4-
import android.app.Application;
5-
import android.content.Context;
6-
import androidx.multidex.MultiDex;
7-
8-
import com.limpoxe.fairy.util.FakeUtil;
9-
import com.limpoxe.fairy.util.LogUtil;
10-
11-
import java.util.List;
12-
13-
public class PluginTestApplication extends Application {
14-
15-
private String packageName;
16-
17-
@Override
18-
public void onCreate() {
19-
super.onCreate();
20-
21-
Context ctx = getApplicationContext();
22-
Log.d("PluginTestApplication", "" + ctx);
23-
24-
if (isApplicationProcess()) {
25-
Log.d("api欺骗成功,让插件以为自己在主进程运行");
26-
}
27-
28-
}
29-
30-
private boolean isApplicationProcess() {
31-
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
32-
List<ActivityManager.RunningAppProcessInfo> list = activityManager.getRunningAppProcesses();
33-
for (ActivityManager.RunningAppProcessInfo appProcess : list) {
34-
if (appProcess.pid == android.os.Process.myPid()) {
35-
if (appProcess.processName.equals(packageName)) {
36-
return true;
37-
}
38-
}
39-
}
40-
return false;
41-
}
42-
43-
@Override
44-
protected void attachBaseContext(Context base) {
45-
super.attachBaseContext(base);
46-
packageName = getPackageName();
47-
MultiDex.install(FakeUtil.fakeMultiDexContext(this));
48-
}
49-
50-
@Override
51-
public void onTerminate() {
52-
super.onTerminate();
53-
LogUtil.e("PluginTestApplication onTerminate");
54-
}
55-
}
1+
package com.example.plugintest
2+
3+
import android.app.ActivityManager
4+
import android.app.ActivityManager.RunningAppProcessInfo
5+
import android.app.Application
6+
import android.content.Context
7+
import android.os.Process
8+
import androidx.multidex.MultiDex
9+
import com.limpoxe.fairy.util.FakeUtil
10+
import com.limpoxe.fairy.util.LogUtil
11+
12+
class PluginTestApplication : Application() {
13+
override fun onCreate() {
14+
super.onCreate()
15+
Log.d("PluginTestApplication onCreate, $applicationContext")
16+
printProcessName()
17+
}
18+
19+
private fun printProcessName() {
20+
val activityManager = getSystemService(ACTIVITY_SERVICE) as ActivityManager
21+
val list = activityManager.runningAppProcesses
22+
for (appProcess in list) {
23+
if (appProcess.pid == Process.myPid()) {
24+
Log.d("PluginTestApplication processName=" + appProcess.processName)
25+
break
26+
}
27+
}
28+
}
29+
30+
override fun attachBaseContext(base: Context) {
31+
super.attachBaseContext(base)
32+
MultiDex.install(FakeUtil.fakeMultiDexContext(this))
33+
}
34+
35+
override fun onTerminate() {
36+
super.onTerminate()
37+
LogUtil.e("PluginTestApplication onTerminate")
38+
}
39+
}

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ buildscript {
1010
}
1111
dependencies {
1212
classpath "com.android.tools.build:gradle:${GRADLE_PLUGIN_VERSION}"
13+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"
1314
// NOTE: Do not place your application dependencies here; they belong
1415
// in the individual module build.gradle files
1516

config.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
ext {
22
CMAKE_VERSION = "3.10.2"
33
NDK_VERSION = "21.1.6352462"
4-
COMPILE_SDK_VERSION = 31
54
BUILD_TOOLS_VERSION = "30.0.3"
5+
COMPILE_SDK_VERSION = 31
66
TARGET_SDK_VERSION = 31
77
MATERIAL_VERSION = "1.6.0"
88
APPCOMPAT_VERSION = "1.4.1"
99
GRADLE_PLUGIN_VERSION = '7.1.3'
1010

1111
//定义常量,方便统一切换脚本的版本
12-
HOST_FAIRY_SCRIPT = "../../FairyPlugin/agp7_1_3/host.gradle"
12+
HOST_FAIRY_SCRIPT = "../../FairyPlugin/agp7_0_3/host.gradle"
1313
//HOST_FAIRY_SCRIPT = "https://raw.githubusercontent.com/limpoxe/Android-Plugin-Framework/master/FairyPlugin/agp${GRADLE_PLUGIN_VERSION.replaceAll("\\.","_")}/host.gradle"
1414

1515
PLUGIN_FAIRY_SCRIPT = "../../FairyPlugin/agp7_1_3/plugin.gradle"
1616
//PLUGIN_FAIRY_SCRIPT = "https://raw.githubusercontent.com/limpoxe/Android-Plugin-Framework/master/FairyPlugin/agp${GRADLE_PLUGIN_VERSION.replaceAll("\\.","_")}/plugin.gradle"
1717

18-
1918
}

0 commit comments

Comments
 (0)