Расширения Kotlin для Android и AndroidX не работают - PullRequest
0 голосов
/ 26 октября 2018

Когда я пытаюсь использовать AndroidX для своего проекта Android / Kotlin, в моем коде происходит сбой многих видов, восстановленных KAE (несоответствие типов), поскольку все они определены с типом View!.

Например, здесь: enter image description here

или здесь:

enter image description here

Что случилось?

Это макет, где находится моя панель инструментов:

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.DrawerLayout
        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/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:openDrawer="start">

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

        <android.support.design.widget.AppBarLayout
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary"
                    app:popupTheme="@style/AppTheme.PopupOverlay"/>

        </android.support.design.widget.AppBarLayout>

        <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/framelayout"/>

    </LinearLayout>

    <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@color/navbar_background"
            app:itemTextColor="#FFF"
            app:itemIconTint="#FFF"
            app:itemBackground="@drawable/drawer_selected_item"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header_main"
            app:menu="@menu/menu_drawer"/>

</androidx.core.widget.DrawerLayout>

Это мой Gradle: приложение:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "my.app"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0.1"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.core:core-ktx:1.0.0'

    implementation 'androidx.multidex:multidex:2.0.0'

    implementation 'com.google.firebase:firebase-core:16.0.4'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'

    implementation "org.jetbrains.anko:anko-commons:0.10.5"
    implementation "org.jetbrains.anko:anko-design:0.10.4"
    implementation "org.jetbrains.anko:anko-sdk25:0.10.5"
    implementation "com.chibatching.kotpref:kotpref:2.5.0"
    implementation "com.chibatching.kotpref:initializer:2.5.0"

    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'

    implementation "androidx.room:room-runtime:2.1.0-alpha01"
    annotationProcessor "androidx.room:room-compiler:2.1.0-alpha01"
    kapt "androidx.room:room-compiler:2.1.0-alpha01"

    implementation 'com.stripe:stripe-android:8.0.0'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.stripe:stripe-android:8.0.0'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
    implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'

    implementation 'io.card:android-sdk:5.5.0'

    // Smooch
    implementation 'io.smooch:core:5.14.3'
    implementation 'io.smooch:ui:5.14.3'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.squareup.okhttp3:okhttp:3.11.0'
    implementation 'com.google.firebase:firebase-core:16.0.4'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
    implementation 'androidx.annotation:annotation:1.0.0'
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    implementation 'androidx.exifinterface:exifinterface:1.0.0'
    implementation 'androidx.media:media:1.0.0'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0'
}

apply plugin: 'com.google.gms.google-services'

1 Ответ

0 голосов
/ 26 октября 2018

Я нашел решение, редактирующее мои файлы макетов. Использование com.google.android.material.appbar.AppBarLayout вместо android.support.design.widget.AppBarLayout. Или используя androidx.appcompat.widget.Toolbar вместо android.support.v7.widget.Toolbar.

К сожалению, все приходится делать вручную ...

Вот пример:

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
        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/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:openDrawer="start">

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

        <com.google.android.material.appbar.AppBarLayout
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:theme="@style/AppTheme.AppBarOverlay">

            <androidx.appcompat.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary"
                    app:popupTheme="@style/AppTheme.PopupOverlay"/>

        </com.google.android.material.appbar.AppBarLayout>

        <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/framelayout"/>

    </LinearLayout>

    <com.google.android.material.navigation.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@color/navbar_background"
            app:itemTextColor="#FFF"
            app:itemIconTint="#FFF"
            app:itemBackground="@drawable/drawer_selected_item"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header_main"
            app:menu="@menu/menu_drawer"/>

</androidx.drawerlayout.widget.DrawerLayout>
...