2

我下载了 Android Studio 4.0(金丝雀频道),我正在尝试创建一个动作布局,但编辑器是灰色的,这个错误通常意味着依赖项有问题。我已经更新了我能想到的所有相关内容(如下所示),并且我已经重建了项目(还完成了使缓存无效并重新启动),但问题仍然存在。我错过了什么?

build.gradle(应用程序):

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.android.aboutme"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding{
        enabled = true
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.60-eap-25"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

build.gradle(项目):

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
        maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.0-alpha01'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.60-eap-25"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }

    }
}

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

xml:

<?xml version="1.0" encoding="utf-8"?>
<!-- activity_main.xml -->
<androidx.constraintlayout.motion.widget.MotionLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/motionLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutDescription="@xml/so_scene"
    tools:showPaths="true">

    <View
        android:id="@+id/button"
        android:layout_width="64dp"
        android:layout_height="64dp"
        android:background="@color/colorAccent"
        android:text="Button" />

</androidx.constraintlayout.motion.widget.MotionLayout>
4

1 回答 1

4

Try to delete app/build/ directory and rebuild project then.

I had a problem like you describe though the issue was not with dependencies, but with MotionLayout class initialization in Motion Editor. You may check messages by clicking icon at the top right of Motion Editor (icon might be "info" or "warning"), like here:

Warnings button in UI Editor

I can't reproduce the error I had, but it was about missing attribute motion_base in MotionScene initialization. Removing the app/build/ dir and getting it regenerated solved the issue.

于 2019-11-02T12:41:32.240 回答