【问题标题】:Couldn't inline method call 'Column' into local final fun <anonymous>() in Jetpack compose无法将方法调用“列”内联到 Jetpack compose 中的本地最终乐趣 <anonymous>()
【发布时间】:2021-05-14 16:35:14
【问题描述】:

我正在使用 Android studio 2020.3.1 Canary 15 在 jetpack compose 中启动一个简单的基础项目。我遵循了本指南https://developer.android.com/jetpack/compose/setup 并添加了所需的依赖项,我还将它们更新为最新的beta06,因为它显示了警告。

现在,我运行时出现以下错误:

org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call 'Column' into
local final fun <anonymous>(): kotlin.Unit defined in <packagename>.onCreate
{
            Column(
                modifier = Modifier.fillMaxSize(),
                verticalArrangement = Arrangement.Center,
                horizontalAlignment = Alignment.CenterHorizontally
            ) {

            }
        }
Cause: Not generated

我的项目级别build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.0-alpha15"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我的应用等级build.gradle

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdk 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.<packagename>"
        minSdk 21
        targetSdk 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    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'
    }

    composeOptions {
        kotlinCompilerExtensionVersion "1.0.0-beta06"
    }
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    implementation 'androidx.compose.ui:ui:1.0.0-beta06'
    // Tooling support (Previews, etc.)
    implementation 'androidx.compose.ui:ui-tooling:1.0.0-beta06'
    // Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
    implementation 'androidx.compose.foundation:foundation:1.0.0-beta06'
    // Material Design
    implementation 'androidx.compose.material:material:1.0.0-beta06'
    // Material design icons
    implementation 'androidx.compose.material:material-icons-core:1.0.0-beta06'
    implementation 'androidx.compose.material:material-icons-extended:1.0.0-beta06'
    // Integration with activities
    implementation 'androidx.activity:activity-compose:1.3.0-alpha07'
    // Integration with ViewModels
    implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha04'
    // Integration with observables
    implementation 'androidx.compose.runtime:runtime-livedata:1.0.0-beta06'
    implementation 'androidx.compose.runtime:runtime-rxjava2:1.0.0-beta06'
}

我的MainActivity 发生错误的代码:

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            Column(
                modifier = Modifier.fillMaxSize(),
                verticalArrangement = Arrangement.Center,
                horizontalAlignment = Alignment.CenterHorizontally
            ) {

            }
        }
    }
}

我已经尝试过了:java.lang.AssertionError: CALL 'public final fun <get-currentComposer>

还有其他这样的答案,但对我没有用。

非常感谢任何帮助。谢谢。

【问题讨论】:

  • alpha15 已经很老了。您是否尝试过升级到 beta07?如果这仍然重现,请考虑将其报告为错误,以便对其进行跟踪和修复。
  • @chuckj 上面写着Could not find com.android.tools.build:gradle:7.0.0-beta07,后面跟着一些长网址。这是你想让我更新的吗?
  • 我看错了。您正在使用beta06beta07 刚刚发布,可能会解决这个问题。如果没有,请提交错误,以便跟踪和修复。
  • @chuckj 注意到。我试试看

标签: android android-jetpack-compose


【解决方案1】:

请尝试将其添加到 android 块内的应用级 build.gradle 文件中

buildFeatures {
        compose true
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多