android-studio - 无法在 Android Studio 新项目中解析“import android.support.v7.widget.GridLayout;”
问题描述
我尝试使用 GridLayout 作为
GridLayout maingrid=(GridLayout)findViewById(R.id.mainGridView);
但它使我的应用程序崩溃。针对这个问题上网冲浪给出了我应该使用的解决方案
android.support.v7.widget.GridLayout;
而不是android.widget.GridLayout;
但在使用这个时我得到错误无法解决v7。
搜索此问题并获得了许多更新build.gradle文件的解决方案,但它也因构建而失败。
build.gradle 文件最初:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
implementation 'com.android.support:cardview-v7:21.+'
implementation 'com.android.support:recyclerview-v7:21.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
更新后:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 26
}
}
请帮我解决这个问题
解决方案
您不得将依赖项添加到 Project/build.gradle。
您必须将它们添加到 Project/app/build.gradle。
您必须将这些移动到块中的 Project/app/build.gradle dependencies
:
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.1'
推荐阅读
- c++ - 二进制文件处理程序未写入最后一个值
- java - 将日期数组转换为整数数组
- sql - 如何在postgresql中获得没有不必要区域的大小
- python - Python multiprocessing module freeze_support() line can obmitted error Windows
- tensorflow - 我可以在 Keras 中循环定义模型吗?
- angular - 无法通过 POSTMAN 访问 Angular 路由
- python - 双向 LSTM 模型尚未建立错误
- java - 具有多个资源和 else 语句的 try-with-resources JDBC
- sql - 如何在加入后对多个列进行区分,然后为每个组排序并选择最新的?
- javascript - Leaflet.js 循环点击事件处理程序