ОШИБКА: не удалось разрешить: viewpager - как это исправить? - PullRequest
0 голосов
/ 04 марта 2019

Я пытаюсь использовать viewpager в моем приложении, которое использовало androidX, но оно показало мне ошибку ERROR: Failed to resolve: viewpager Affected Modules: app после добавления implementation 'android.viewpager:viewpager:1.0.0' и синхронизации проекта Gradle.Я много искал, но не нашел решения. Пожалуйста, помогите заранее. Есть файл XML.

Файл XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".Favourites.FavouriteLinks">
    <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_chainStyle="spread_inside"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            tools:layout_conversion_absoluteHeight="56dp"
            tools:layout_conversion_absoluteWidth="384dp" android:layout_marginBottom="8dp"
            app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintVertical_bias="0.0">

        <TextView
                android:id="@+id/toolbar_title"
                style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="casual"
                android:gravity="left"
                android:text="Favourites Brochures"
                android:textColor="@color/colorwhite"
                android:textSize="18sp"
                android:textStyle="bold"
                tools:layout_conversion_absoluteHeight="28dp"
                tools:layout_conversion_absoluteWidth="56dp"
                tools:layout_editor_absoluteX="16dp"
                tools:layout_editor_absoluteY="14dp"/>
    </androidx.appcompat.widget.Toolbar>

    <com.google.android.material.tabs.TabLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            app:tabSelectedTextColor="@android:color/white"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginTop="32dp"
            app:layout_constraintTop_toTopOf="@+id/toolbar"
            android:layout_marginBottom="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintVertical_bias="0.04000002" android:id="@+id/tabLayout">

        <com.google.android.material.tabs.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="21sp"
                android:textStyle="bold"
                android:text="tab2"
        />

        <com.google.android.material.tabs.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="tab1"
                android:textSize="21sp"
                android:textStyle="bold"
        />
    </com.google.android.material.tabs.TabLayout>
    <androidx.viewpager.widget.ViewPager
            android:id="@+id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="508dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginBottom="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            android:layout_marginTop="8dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintVertical_bias="0.85"/>


</androidx.constraintlayout.widget.ConstraintLayout>

код Котлина

class FavouriteLinks : AppCompatActivity() {

    //This is our viewPager
    var viewPager: ViewPager? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_favourite_links)
        setSupportActionBar(toolbar)
        supportActionBar?.setDisplayShowTitleEnabled(false)


        viewPager = findViewById<ViewPager>(R.id.viewPager)

        val pageAdapter = PageAdapter(supportFragmentManager, tabLayout.tabCount)
        viewPager?.adapter = pageAdapter

    }
}

файл Gradle

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

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.nanotech.i_cardplatform"
        minSdkVersion 17
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    //noinspection GradleCompatible
    implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
    implementation 'com.google.android.material:material:1.0.0-alpha1'
    //RETROFIT ...  NETWORK LIBRARY
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    // RETROFIT .. CONVERTER
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    // Logging
    implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
    implementation 'com.squareup.retrofit2:converter-scalars:2.3.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'

    // Room dependencies
    implementation 'androidx.room:room-runtime:2.0.0-alpha1'
    kapt 'androidx.room:room-compiler:2.0.0-alpha1'
    annotationProcessor 'androidx.room:room-compiler:2.0.0-alpha1'
    implementation 'com.squareup.picasso:picasso:2.5.2'

    implementation 'androidx.viewpager:viewpager:1.0.0'
}
repositories {
    mavenCentral()
}

1 Ответ

0 голосов
/ 05 марта 2019

Не добавляйте библиотеку viewPager отдельно, она уже включена в

implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
...