简体   繁体   English

当我在Gradle中导入Android-ktx时,无法合成kotlin扩展

[英]Synthetic of kotlin extensions does not work when I import Android-ktx in gradle

I'm trying to test some android jetpack features in my project, I already have the navigation working. 我正在尝试在我的项目中测试一些android jetpack功能,我已经在使用导航功能。 When I tried to import android-ktx and migrate my dependencies to androidx I managed to synchronize the gradle successfully, but I lost access to my button through synthetic. 当我尝试导入android-ktx并将依赖项迁移到androidx时,我成功地成功同步了gradle,但是我无法通过合成访问按钮。

Anyone have any idea what it can be? 有人知道它可以是什么吗?

My Gradle: 我的摇篮:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.qmakercorp.qmaker"
        minSdkVersion 22
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.support.test.runner.AndroidJUnitRunner"
    }

    androidExtensions {
        experimental = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.71"
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'

//    implementation 'com.android.support:appcompat-v7:28.0.0'
//    implementation 'com.android.support:design:28.0.0'
//    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
//    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//    implementation 'com.android.support:support-v4:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-beta01'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-beta01'

    implementation "android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha06"
    implementation "android.arch.navigation:navigation-ui-ktx:1.0.0-alpha06"
    androidTestImplementation 'androidx.test:rules:1.1.0-beta01' 

    implementation 'androidx.core:core-ktx:1.0.0'

My Fragment: 我的片段:

从片段打印

In your app build.gradle file you imported androidx.legacy:legacy-support-v4:1.0.0 and clicked Sync Now . 在您的应用程序build.gradle文件中,您导入了androidx.legacy:legacy-support-v4:1.0.0并点击Sync Now After that you had error saying Manifest merger failed : Attribute bla bla ... and commented com.android.support:support-v4:28.0.0 but there wasn't shown Sync Now and you didn't sync your project with gradle files. 之后,出现错误,提示Manifest merger failed : Attribute bla bla ...并评论了com.android.support:support-v4:28.0.0但未显示“ Sync Now ,也没有将您的项目与gradle文件同步。 That's way you still able to use android.support.v4.app.Fragment from LoginFragment . 这样,您仍然可以使用LoginFragment android.support.v4.app.Fragment Suggestion: click Sync Project with Gradle Files button and replace import android.support.v4.app.Fragment with import androidx.fragment.app.Fragment . 建议:单击Sync Project with Gradle Files按钮,然后将import android.support.v4.app.Fragment替换为import androidx.fragment.app.Fragment

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM