首页 > 解决方案 > 构建完成并运行,但在类 android 上显示错误

问题描述

我在 android studio 上有一些奇怪的错误/错误,我的应用程序 gradle 是完整的并且在设备上运行顺利,但是它显示的错误,比如我的库没有完全包含在 android studio 中,我已经这样做了

  1. 清洁然后重建
  2. 使缓存无效并重新启动

但没有任何效果,这是截图 导入错误以及使用该类的所有内容

成功等级

这是我的应用程序 Gradle

android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
    applicationId "com.host.appname"
    minSdkVersion 15
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
    useLibrary 'org.apache.http.legacy'
    vectorDrawables.useSupportLibrary = true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        lintOptions {
            disable 'MissingTranslation'
        }
    }
}
productFlavors {
}
packagingOptions {
    exclude 'META-INF/NOTICE.txt' // will not include NOTICE file
    exclude 'META-INF/LICENSE.txt' // will not include LICENSE file
}

这是我的项目 gradle

    buildscript {
        repositories {
            jcenter()
            flatDir {
                dirs 'libs'
            }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.3'
        }
    }

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

所以我可以运行我的应用程序,我可以使用它,但它对我来说真的很烦人,因为我不能对错误库和到处的红色标记使用自动完成。

谢谢你..

标签: androidgradleandroid-appcompat

解决方案


  1. 删除这些行并从正确/兼容的包中重新导入它们。
  2. 尝试删除所有依赖项然后同步并再次添加所有依赖项然后同步。

正如您在评论 nimi0112Ali Ahmed中提到的那样,您的回答确实对我帮助很大。


推荐阅读