android - 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'
}
解决方案
据我从警告中看到的,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"/>
如果它不起作用,请通过评论告诉我。
推荐阅读
- primefaces - json 传递的日期不正确,如“jsonObject.toString()”
- c# - 生成 CSV 时强制 Servicestack 分隔字段
- java - 我不能 @Autowired 一个 DatastoreRepository bean(Goolge 云数据存储)
- google-cloud-platform - 将虚拟机实例添加到实例组
- node.js - 写一个带有变量值名称的 ini 键
- android-fragments - 由于处理程序,片段未附加到上下文?
- django - 如何在 Django 中的应用程序之间迁移模型?
- reactjs - 使用 React Google Maps 显示路线
- javascript - React setState() 不会在回调中返回更新的状态
- amazon-web-services - Kops 创建集群因 AWS Linux 中的八卦而失败