我使用 Jetpack Compose 1.0.0-beta08 中的默认排版。但是logcat给了我这样的错误信息:
java.lang.NoSuchMethodError: No static method copy-H99Ercs$default(Landroidx/compose/ui/text/TextStyle;JJLandroidx/compose/ui/text/font/FontWeight;Landroidx/compose/ui/text/font/FontStyle;Landroidx/compose/ui/text/font/FontSynthesis;Landroidx/compose/ui/text/font/FontFamily;Ljava/lang/String;JLandroidx/compose/ui/text/style/BaselineShift;Landroidx/compose/ui/text/style/TextGeometricTransform;Landroidx/compose/ui/text/intl/LocaleList;JLandroidx/compose/ui/text/style/TextDecoration;Landroidx/compose/ui/graphics/Shadow;Landroidx/compose/ui/text/style/TextAlign;Landroidx/compose/ui/text/style/TextDirection;JLandroidx/compose/ui/text/style/TextIndent;ILjava/lang/Object;)Landroidx/compose/ui/text/TextStyle; in class Landroidx/compose/ui/text/TextStyle; or its super classes (declaration of 'androidx.compose.ui.text.TextStyle' appears in /data/app/~~dzGPwRcTH3NcPitRFMz-4g==/cn.phakel.fighting-5iN5DgNNOwwUjTIkZ-2A6Q==/base.apk)
at androidx.compose.material.TypographyKt.withDefaultFontFamily(Typography.kt:284)
at androidx.compose.material.TypographyKt.access$withDefaultFontFamily(Typography.kt:1)
at androidx.compose.material.Typography.<init>(Typography.kt:186)
at androidx.compose.material.Typography.<init>(Typography.kt:118)
at cn.phakel.fighting.ui.theme.TypeKt.<clinit>(Type.kt:10)
at cn.phakel.fighting.ui.theme.TypeKt.getTypography(Type.kt:10)
at cn.phakel.fighting.ui.theme.ThemeKt.FightingTheme(Theme.kt:36)
at cn.phakel.fighting.ComposableSingletons$MainActivityKt$lambda-3$1.invoke(MainActivity.kt:19)
at cn.phakel.fighting.ComposableSingletons$MainActivityKt$lambda-3$1.invoke(MainActivity.kt:18)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
这是我的 Type.kt:val Typography = Typography(
body1 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp
),
button = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.W500,
fontSize = 14.sp
),
caption = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 12.sp
)
)
主题.kt:@Composable
fun FightingTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable() () -> Unit) {
val colors = if (darkTheme) {
DarkColorPalette
} else {
LightColorPalette
}
MaterialTheme(
colors = colors,
typography = Typography,
shapes = Shapes,
content = content
)
}
MainActivity.kt:class MainActivity : ComponentActivity() {
@ExperimentalPagerApi
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
FightingTheme {
Surface(color = MaterialTheme.colors.background) {
val navController = rememberNavController()
Home(navController = navController)
}
}
}
}
}
项目的 Gradle 设置:buildscript {
ext {
compose_version = '1.0.0-beta08'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0-beta04'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
模块的 Gradle 设置:plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "cn.phakel.fighting"
minSdk 21
targetSdk 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.4.32'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.0-beta01'
testImplementation 'junit:junit:4.+'
implementation 'com.google.code.gson:gson:2.8.7'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
implementation 'com.google.accompanist:accompanist-pager:0.11.1'
implementation 'com.google.accompanist:accompanist-pager-indicators:0.9.1'
implementation 'com.google.accompanist:accompanist-coil:0.11.0'
implementation 'io.github.openfeign:feign-okhttp:10.11'
implementation 'io.github.openfeign:feign-gson:10.11'
implementation 'io.github.openfeign:feign-slf4j:10.11'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
implementation 'androidx.navigation:navigation-compose:2.4.0-alpha03'
}
gradle.propertiesorg.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=true
android.enableJetifier=true
kotlin.code.style=official
设置.gradle:dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
rootProject.name = "Fighting"
include ':app'
我认为这可能是由错误的版本引起的。但我不知道如何解决这个问题。如果您知道,请告诉我如何解决此问题。
最佳答案
我刚刚遇到了同样的问题,我认为他们只是解决了它。
ext {
compose_version = '1.0.0-beta09'
}
关于android - 无法在 Jetpack Compose 中设置排版,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68033451/