【问题标题】:Could not resolve "import android.support.v7.widget.GridLayout; " in Android Studio new project无法在 Android Studio 新项目中解析“import android.support.v7.widget.GridLayout;”
【发布时间】:2019-12-04 22:51:27
【问题描述】:

我尝试将 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
    }
}

请帮我解决这个问题

【问题讨论】:

  • 可能有些java文件包含android.support.v7.widget.GridLayout;顶部的 import 语句尝试手动删除它们

标签: android-studio android-layout android-support-library android-gridlayout


【解决方案1】:

不得将依赖项添加到 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'

【讨论】:

    猜你喜欢
    • 2018-07-23
    • 2014-09-19
    • 2013-09-01
    • 2018-05-07
    • 1970-01-01
    • 2016-06-22
    • 2013-06-10
    • 1970-01-01
    • 2012-09-10
    相关资源
    最近更新 更多