【问题标题】:Dependency Changes For Oreo Gives ErrorOreo 的依赖关系更改给出错误
【发布时间】:2018-02-01 14:47:08
【问题描述】:

build.gradle依赖改为

 compile 'com.android.support:design:26.1.0'

here 所述,项目构建成功,但是当我尝试运行时,它会出现类似的错误

错误:找不到符号变量 super

错误:找不到符号方法 findViewById(int)

错误:找不到符号方法finish()

错误:找不到符号方法getResources()

错误:找不到符号方法 setContentView(int)

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.example.myApp"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    android {
        useLibrary 'org.apache.http.legacy'
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
}

dependencies {
    compile 'com.android.support:multidex:1.0.1'
    compile fileTree(dir: 'libs', include: ['*.jar'])


    testCompile 'junit:junit:4.12'

    compile 'com.android.support:design:26.1.0'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
  }
allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com'
        }
        maven { url "https://jitpack.io" }
    }
}

【问题讨论】:

  • 如何将另外两个支持库 support-v4cardview-v7 更新为 26.1.0 并执行干净的构建?
  • 也更改这两个库编译'com.android.support:support-v13:26.1.0'并编译'com.android.support:cardview-v7:26.1.0'但错误保持不变.
  • clean了吗?
  • 是的,我会清理并且还会使 android studio 失效并重新启动。
  • 你能发布出现这些错误的类吗?由于运行时出现错误,请同时贴出logcat

标签: android dependencies android-gradle-plugin build.gradle


【解决方案1】:

更改我的依赖项后问题解决。

compile 'com.android.support:design:26.1.0'
compile 'com.android.support:support-v13:26.1.0'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'

构建版本如下所示。

compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }

问题是因为 ActionbarActivity。我有一些扩展 ActionbarActivity 的活动。 所以只是将 Actionbaractivity 替换为 Appcompact Activity。

请注意: android 开发者文档说:“将 AppCompatActivity 更新为使用支持库操作栏功能的 Activity 的基类。此类替换了已弃用的 ActionBarActivity。”

【讨论】:

    【解决方案2】:

    在模块的java 文件夹中创建新类:
    包结构:

    java / 安卓/支持/v7/应用/

    package android.support.v7.app;
    
    public class ActionBarActivity extends AppCompatActivity {
    }
    

    在项目级 build.gradle 中添加以下内容:

    defaultConfig {
            multiDexEnabled true
    
    }
    

    内部依赖:

       compile 'com.android.support:multidex:1.0.1'
    

    【讨论】:

      猜你喜欢
      • 2017-04-10
      • 2017-04-03
      • 1970-01-01
      • 2020-07-07
      • 1970-01-01
      • 2020-03-10
      • 1970-01-01
      • 2022-01-23
      • 2021-10-25
      相关资源
      最近更新 更多