提交 98790f7c authored 作者: JarvanMo's avatar JarvanMo

refactor app_id generate

上级 0176e8c3
...@@ -3,6 +3,8 @@ import org.yaml.snakeyaml.Yaml ...@@ -3,6 +3,8 @@ import org.yaml.snakeyaml.Yaml
group 'com.jarvan.fluwx' group 'com.jarvan.fluwx'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
Map projectYaml = loadPubspec()
buildscript { buildscript {
ext.kotlin_version = '1.7.10' ext.kotlin_version = '1.7.10'
repositories { repositories {
...@@ -31,14 +33,14 @@ android { ...@@ -31,14 +33,14 @@ android {
compileSdk 31 compileSdk 31
sourceSets { sourceSets {
main.java.srcDirs += 'src/main/kotlin' main.java.srcDirs += ['src/main/kotlin',"${buildDir}/generated/main/kotlin"]
test.java.srcDirs += 'src/test/kotlin' test.java.srcDirs += 'src/test/kotlin'
} }
defaultConfig { defaultConfig {
minSdkVersion 16 minSdkVersion 16
consumerProguardFiles 'consumer-proguard-rules.txt' consumerProguardFiles 'consumer-proguard-rules.txt'
manifestPlaceholders = loadManifestPlaceholder() manifestPlaceholders = loadManifestPlaceholder(projectYaml)
} }
dependencies { dependencies {
...@@ -64,12 +66,16 @@ android { ...@@ -64,12 +66,16 @@ android {
} }
} }
Map loadManifestPlaceholder() { Map loadPubspec() {
def path = rootProject.projectDir.parent + File.separator + "pubspec.yaml" def path = rootProject.projectDir.parent + File.separator + "pubspec.yaml"
InputStream input = new FileInputStream(new File(path)) InputStream input = new FileInputStream(new File(path))
Yaml yaml = new Yaml() Yaml yaml = new Yaml()
Map projectConfig = yaml.load(input) Map projectConfig = yaml.load(input)
String appId = ""
return projectConfig
}
static def loadManifestPlaceholder(Map projectConfig) {
String interruptWxRequest = "true" String interruptWxRequest = "true"
String flutterActivity = "" String flutterActivity = ""
String debugLogging = "disabled" String debugLogging = "disabled"
...@@ -95,8 +101,37 @@ Map loadManifestPlaceholder() { ...@@ -95,8 +101,37 @@ Map loadManifestPlaceholder() {
} }
return ["WeChatAppId": appId, return ["InterruptWeChatRequestByFluwx": interruptWxRequest,
"InterruptWeChatRequestByFluwx": interruptWxRequest, "FluwxFlutterActivity" : flutterActivity,
"FluwxFlutterActivity": flutterActivity, "WeChatDebugLogging" : debugLogging]
"WeChatDebugLogging": debugLogging] }
tasks.register("generateFluwxHelperFile") {
Map config = loadPubspec()
Map fluwx = (Map) config.get("fluwx")
if (fluwx) {
String appId = (String) fluwx.get("app_id")
if (appId == null) {
appId = ""
}
File generateFolder = new File("${buildDir}/generated/main/kotlin/com/jarvan/fluwx")
String template = "package com.jarvan.fluwx\n" +
"// auto generated\n" +
"object FluwxHelper {\n" +
" val appId:String =\"&&PLACEHOLDER&&\";\n" +
"}"
if (!generateFolder.exists()) {
generateFolder.mkdirs()
}
file("${generateFolder.absolutePath}/FluwxHelper.kt").text = template.replace("&&PLACEHOLDER&&", appId)
}
} }
tasks.named("build").configure {
dependsOn("generateFluwxHelperFile")
}
\ No newline at end of file
...@@ -12,10 +12,6 @@ ...@@ -12,10 +12,6 @@
<application> <application>
<meta-data
android:name="WeChatAppId"
android:value="${WeChatAppId}" />
<meta-data <meta-data
android:name="InterruptWeChatRequestByFluwx" android:name="InterruptWeChatRequestByFluwx"
android:value="${InterruptWeChatRequestByFluwx}" /> android:value="${InterruptWeChatRequestByFluwx}" />
......
...@@ -19,6 +19,7 @@ import android.app.Activity ...@@ -19,6 +19,7 @@ import android.app.Activity
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Bundle import android.os.Bundle
import com.jarvan.fluwx.FluwxHelper
import com.jarvan.fluwx.handlers.FluwxResponseHandler import com.jarvan.fluwx.handlers.FluwxResponseHandler
import com.jarvan.fluwx.handlers.FluwxRequestHandler import com.jarvan.fluwx.handlers.FluwxRequestHandler
import com.jarvan.fluwx.handlers.WXAPiHandler import com.jarvan.fluwx.handlers.WXAPiHandler
...@@ -39,9 +40,8 @@ open class FluwxWXEntryActivity : Activity(), IWXAPIEventHandler { ...@@ -39,9 +40,8 @@ open class FluwxWXEntryActivity : Activity(), IWXAPIEventHandler {
try { try {
if (!WXAPiHandler.wxApiRegistered) { if (!WXAPiHandler.wxApiRegistered) {
val appInfo = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA) val wechatAppId = FluwxHelper.appId
val wechatAppId = appInfo.metaData.getString("WeChatAppId") if (wechatAppId.isNotBlank()) {
if (wechatAppId != null) {
WXAPiHandler.setupWxApi(wechatAppId,this) WXAPiHandler.setupWxApi(wechatAppId,this)
WXAPiHandler.coolBoot = true WXAPiHandler.coolBoot = true
} else { } else {
......
...@@ -16,14 +16,6 @@ ...@@ -16,14 +16,6 @@
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="fluwx_example"> android:label="fluwx_example">
<meta-data
android:name="weChatAppId"
android:value="12345678" />
<meta-data
android:name="handleWeChatRequestByFluwx"
android:value="true" />
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论