首页 > 解决方案 > How to implement GridLayout in Androidx?

问题描述

I tried to implement the GridLayout by downloading it directly via android studio but I get this error:

Show Details
Affected Modules: app

ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not download gridlayout.aar (androidx.gridlayout:gridlayout:1.0.0)
Show Details
Affected Modules: app

ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not download gridlayout.aar (androidx.gridlayout:gridlayout:1.0.0)
Show Details
Affected Modules: app

I already tried to set the Global Gradle settings to offline work but a new error is displayed

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not download gridlayout.aar (androidx.gridlayout:gridlayout:1.0.0): No cached version available for offline mode
Disable offline mode and sync project
Show Details
Affected Modules: app

Is GridLayout not yet available for android Studio?

Here is my Gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.0"
    defaultConfig {
        applicationId "com.example.android.guessit"
        minSdkVersion 17
        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'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    //Glide maybe later add code to proguard
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'

    // circle imageview
    implementation 'de.hdodenhof:circleimageview:3.0.0'

    // cardview

    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.gridlayout:gridlayout:1.0.0'
}

标签: androidandroidxandroid-gridlayout

解决方案


据我从警告中看到的,gridlayout lib 没有任何问题。如果你想让它工作,你需要从 Android Studio中禁用离线工作。要禁用它,请按照以下步骤操作:

“Gradle 处于离线模式,这意味着它不会去网络解决依赖关系。转到 Preferences > Build, Execution, Deployment > Gradle 并取消选中“Offline work”。在 Android Studio 中打开设置并搜索离线它将找到包含离线工作的 Gradle 类别。您可以在那里禁用它。 在此处输入图像描述

然后,您可以使用网格布局

 <androidx.gridlayout.widget.GridLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

如果它不起作用,请通过评论告诉我。


推荐阅读