mirror of
https://github.com/OpenFlutter/fluwx.git
synced 2025-05-17 15:25:59 +08:00
refactor app_id generate
This commit is contained in:
@ -3,6 +3,8 @@ import org.yaml.snakeyaml.Yaml
|
||||
group 'com.jarvan.fluwx'
|
||||
version '1.0-SNAPSHOT'
|
||||
|
||||
Map projectYaml = loadPubspec()
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.7.10'
|
||||
repositories {
|
||||
@ -31,14 +33,14 @@ android {
|
||||
compileSdk 31
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'src/main/kotlin'
|
||||
main.java.srcDirs += ['src/main/kotlin',"${buildDir}/generated/main/kotlin"]
|
||||
test.java.srcDirs += 'src/test/kotlin'
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
consumerProguardFiles 'consumer-proguard-rules.txt'
|
||||
manifestPlaceholders = loadManifestPlaceholder()
|
||||
manifestPlaceholders = loadManifestPlaceholder(projectYaml)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@ -64,12 +66,16 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
Map loadManifestPlaceholder() {
|
||||
Map loadPubspec() {
|
||||
def path = rootProject.projectDir.parent + File.separator + "pubspec.yaml"
|
||||
InputStream input = new FileInputStream(new File(path))
|
||||
Yaml yaml = new Yaml()
|
||||
Map projectConfig = yaml.load(input)
|
||||
String appId = ""
|
||||
|
||||
return projectConfig
|
||||
}
|
||||
|
||||
static def loadManifestPlaceholder(Map projectConfig) {
|
||||
String interruptWxRequest = "true"
|
||||
String flutterActivity = ""
|
||||
String debugLogging = "disabled"
|
||||
@ -95,8 +101,37 @@ Map loadManifestPlaceholder() {
|
||||
|
||||
}
|
||||
|
||||
return ["WeChatAppId": appId,
|
||||
"InterruptWeChatRequestByFluwx": interruptWxRequest,
|
||||
"FluwxFlutterActivity": flutterActivity,
|
||||
"WeChatDebugLogging": debugLogging]
|
||||
return ["InterruptWeChatRequestByFluwx": interruptWxRequest,
|
||||
"FluwxFlutterActivity" : flutterActivity,
|
||||
"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")
|
||||
}
|
@ -12,10 +12,6 @@
|
||||
|
||||
<application>
|
||||
|
||||
<meta-data
|
||||
android:name="WeChatAppId"
|
||||
android:value="${WeChatAppId}" />
|
||||
|
||||
<meta-data
|
||||
android:name="InterruptWeChatRequestByFluwx"
|
||||
android:value="${InterruptWeChatRequestByFluwx}" />
|
||||
|
@ -19,6 +19,7 @@ import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import com.jarvan.fluwx.FluwxHelper
|
||||
import com.jarvan.fluwx.handlers.FluwxResponseHandler
|
||||
import com.jarvan.fluwx.handlers.FluwxRequestHandler
|
||||
import com.jarvan.fluwx.handlers.WXAPiHandler
|
||||
@ -39,9 +40,8 @@ open class FluwxWXEntryActivity : Activity(), IWXAPIEventHandler {
|
||||
|
||||
try {
|
||||
if (!WXAPiHandler.wxApiRegistered) {
|
||||
val appInfo = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
|
||||
val wechatAppId = appInfo.metaData.getString("WeChatAppId")
|
||||
if (wechatAppId != null) {
|
||||
val wechatAppId = FluwxHelper.appId
|
||||
if (wechatAppId.isNotBlank()) {
|
||||
WXAPiHandler.setupWxApi(wechatAppId,this)
|
||||
WXAPiHandler.coolBoot = true
|
||||
} else {
|
||||
|
@ -16,14 +16,6 @@
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="fluwx_example">
|
||||
|
||||
<meta-data
|
||||
android:name="weChatAppId"
|
||||
android:value="12345678" />
|
||||
|
||||
<meta-data
|
||||
android:name="handleWeChatRequestByFluwx"
|
||||
android:value="true" />
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
|
Reference in New Issue
Block a user