首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在Jetpack构图中设置排版

无法在Jetpack构图中设置排版
EN

Stack Overflow用户
提问于 2021-06-18 10:21:06
回答 3查看 3.9K关注 0票数 10

我在Jetpack中使用默认的排版,组成1.0.0-beta08。但是logcat给了我这样的错误信息:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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
    )
)

Theme.kt:

代码语言:javascript
复制
@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:

代码语言:javascript
复制
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)
            }
        }
    }
}
}

项目分级设置:

代码语言:javascript
复制
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
}
}

模块的分级设置:

代码语言:javascript
复制
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.properties

代码语言:javascript
复制
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=true
android.enableJetifier=true
kotlin.code.style=official

settings.gradle:

代码语言:javascript
复制
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'

我认为这可能是由错误的版本造成的。但我不知道怎么解决这个问题。如果你知道的话请告诉我怎么解决这个问题。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2021-06-18 14:21:46

我只是遇到了同样的问题,我想他们只是解决了它。

代码语言:javascript
复制
ext {
    compose_version = '1.0.0-beta09'
}
票数 31
EN

Stack Overflow用户

发布于 2021-06-18 17:25:07

在您的Gradle文件,应用程序级别,内部组成选项块,删除Kotlin编译器行。另外,通过更改项目级Gradle文件中的撰写版本来更新以编写beta09

票数 1
EN

Stack Overflow用户

发布于 2021-06-18 15:07:47

我建议的只是安全措施,如上面所述,将您的撰写依赖项升级到最新版本,或者只是升级您的implementation 'androidx.compose.ui:ui:<latestVersion>依赖项。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68033451

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档