【问题标题】:how to fix package android.support.v4.app not exist in androidx projects?如何修复 androidx 项目中不存在包 android.support.v4.app?
【发布时间】:2019-12-20 22:58:04
【问题描述】:

我正在开发一个使用ActionBarSherlock库项目的应用,当前项目使用androidx依赖。

如果 Make Project 会出现 android.support.v4.app 不存在错误。 错误:找不到符号 符号:类 FragmentActivity 错误:包 mFragments 不存在 等等……

我的问题是 1.如何兼容androidx中之前的android.support包? 2.如何正确迁移到使用旧的android支持库的androidx?

我在模块中的 build.gradle 如下: 1. 模块中的build.gradle:ActionBarSherlock 是模块app 的一个lib 项目 应用插件:'com.android.library'

android {
    compileSdkVersion 29


    defaultConfig {
        minSdkVersion 4
        targetSdkVersion 29
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    lintOptions {
        abortOnError false
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
}
  1. app 中的 build.gradle 使用上述 ActionBarSherlock 作为 lib 项目
apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.app"
        minSdkVersion 15
        targetSdkVersion 29
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    compile project(':ActionBarSherlock')
    configurations.compile.exclude module: 'support-v4'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.multidex:multidex:2.0.0'
    implementation 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    implementation 'com.actionbarsherlock:library:4.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

【问题讨论】:

  • 你为什么在 2019 年使用 actionbarsherlock?您的 minsdk 是 15 并且 androidx 支持库能够提供低至该 api 级别的功能。你不需要actionbersherlock
  • 因为我正在对一个使用 actionbarsherlock 的遗留项目进行一些研究和开发。
  • 启用 jetifier 转换库中的 android.* 依赖项
  • 是的,我这样做了。在 gradle.properties 中,我设置了 android.useAndroidX=true android.enableJetifier=true。我已经为此使用了 as mirgate 工具。

标签: java android


【解决方案1】:

ActionBarSherlock 已弃用。没有更多的发展将采取 地点。

正如它在official repository 中所说的那样

所以我提醒你不要使用那个库。

【讨论】:

  • 是的,我需要先运行这个使用 ActionBarSherlock 的遗留项目,然后我想找到一种方法来替换 ActionBarSherlock。请告诉我如何处理。
猜你喜欢
  • 2020-10-29
  • 2018-11-10
  • 1970-01-01
  • 2017-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-24
  • 1970-01-01
相关资源
最近更新 更多