我无法正确地设置应用的主题在颤振。这是flutter_stripe插件所要求的。
我知道我的插件的其余部分工作正常,就像它在iOS上工作一样。
这就是我在Android上遇到的错误:
I/flutter (26094): ----------------FIREBASE CRASHLYTICS---------------- I/flutter (26094): PlatformException(flutter_stripe initialization failed, The plugin failed to initialize: I/flutter (26094): Your theme isn't set to use Theme.AppCompat or Theme.MaterialComponents. I/flutter (26094): Please make sure you follow all the steps detailed inside the README: https://github.com/flutter-stripe/flutter_stripe#android I/flutter (26094): If you continue to have trouble, follow this discussion to get some support https://github.com/flutter-stripe/flutter_stripe/discussions/538, null, null) I/flutter (26094): I/flutter (26094): #0 JSONMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:155:7) I/flutter (26094): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:177:18) I/flutter (26094): <asynchronous suspension> I/flutter (26094): #2 MethodChannelStripe.initialise (package:stripe_platform_interface/src/method_channel_stripe.dart:46:5) I/flutter (26094): <asynchronous suspension> I/flutter (26094): #3 Stripe._initialise (package:flutter_stripe/src/stripe.dart:424:5) I/flutter (26094): <asynchronous suspension> I/flutter (26094): #4 Stripe.initPaymentSheet (package:flutter_stripe/src/stripe.dart:317:5) I/flutter (26094): <asynchronous suspension> I/flutter (26094): #5
_SellTicketsState.makePayment (package:eventiks/Screens/sell_tickets.dart:118:6) I/flutter (26094): <asynchronous suspension> I/flutter (26094):
----------------------------------------------------
我遵循了安卓的这里步骤。
我的app/src/main/res/value/styes.xml如下所示:
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="Theme.MaterialComponents">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
顺便说一句,这是红色的: Theme.AppCompat.Light.NoActionBar & Theme.MaterialComponents,并附有警告:
无法解析符号“Theme.MaterialComponents”无法解析符号“Theme.AppCompat.Light.NoActionBar”
我在网上阅读,发现我应该在gradle文件中添加以下内容:
资料:材料:材料:1.5.0
我的build.gradle看起来是这样的:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion flutter.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "uk.co.eelavan.eventiks"
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.android.material:material:1.5.0'
}
apply plugin: 'com.google.gms.google-services'
我的kotlin插件版本是:
ext.kotlin_version = '1.6.10‘
我做到了,但我还是得到了上面的错误。需要帮助求你了!
发布于 2022-04-11 11:25:57
答案是您必须在两个文件夹中更改style.xml。
价值与价值-夜晚
我两样都换了,现在起作用了!
发布于 2022-04-11 10:05:22
style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<!-- <style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">-->
<style name="NormalTheme" parent="Theme.MaterialComponents">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
MainActivity.kt
package com.flutter.stripe.example
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.android.FlutterFragmentActivity
class MainActivity: FlutterFragmentActivity() {
}
发布于 2022-12-03 14:27:13
这是我用来解决这个问题的代码。
值/styes.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!--
Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame
-->
<item name="android:windowBackground">
@drawable/launch_background
</item>
</style>
<!--
Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding.
-->
<style name="NormalTheme" parent="Theme.MaterialComponents">
<item name="android:windowBackground">
?android:colorBackground
</item>
</style>
</resources>
values night/styes.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<!-- TODO document the necessary change -->
<style name="LaunchTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!--
Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame
-->
<item name="android:windowBackground">
@drawable/launch_background
</item>
</style>
<!--
Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding.
-->
<style name="NormalTheme" parent="Theme.MaterialComponents">
<item name="android:windowBackground">
?android:colorBackground
</item>
</style>
</resources>
希望能帮上忙!
https://stackoverflow.com/questions/71825737
复制相似问题