【问题标题】:Get "error: cannot access FragmentActivity" after upgrade my Android SDK升级我的 Android SDK 后出现“错误:无法访问 FragmentActivity”
【发布时间】:2018-12-11 13:30:37
【问题描述】:

我有一个基于 libuvccamera 库的 Android 应用程序。

我的问题是在将我的 SDK 升级到最新版本后出现的。

当我尝试“制作项目”时,它运行良好。

但是当我尝试运行该项目时,我收到以下错误消息:

错误:无法访问 FragmentActivity

找不到 android.support.v4.app.FragmentActivity 的类文件

注意:某些输入文件使用或覆盖已弃用的 API。

在这个特定的行中:

baseActivity.setPath(path);

这一行是这个函数的一部分:

public void handleUpdateMedia(final String path) {
            if (DEBUG) Log.v(TAG_THREAD, "handleUpdateMedia:path=" + path);
            mHandler.setPath(path);
            final Activity parent=mWeakParent.get();

            BaseActivity baseActivity=(BaseActivity) parent;
            if (baseActivity != null) {
                baseActivity.setPath(path);
            }
            final boolean released=(mHandler == null) || mHandler.mReleased;
            if (parent != null && parent.getApplicationContext() != null) {
                try {
                    if (DEBUG) Log.i(TAG, "MediaScannerConnection#scanFile");
                    MediaScannerConnection.scanFile(parent.getApplicationContext(), new String[]{path}, null, null);
                } catch (final Exception e) {
                    Log.e(TAG, "handleUpdateMedia:", e);
                }
                if (released || parent.isDestroyed())
                    handleRelease();
            } else {
                Log.w(TAG, "MainActivity already destroyed");
                // give up to add this movie to MediaStore now.
                // Seeing this movie on Gallery app etc. will take a lot of time.
                handleRelease();
            }
        }

位于usbCameraCommon 库(libuvccamera 库使用的库之一)中。

还有其他人遇到过这种问题吗?

谢谢

【问题讨论】:

  • 您的 libuvccamera 正在使用已在最新支持库中删除的已弃用的 FragmentActivity 类。您需要使用 AppCompatActivity 对其进行更新。

标签: android-studio android-gradle-plugin android-fragmentactivity


【解决方案1】:

我找到了一个解决方案,但有更好的解决方案,如果有人可以在这里写得更详细,我将不胜感激,我会自己解释。

项目失败的原因是libuvccamera项目的gradle文件中implementationapi的错误使用。

我刚刚对所有依赖项项目使用了implementation,现在我知道这是错误的,但我仍然不明白它们之间的区别。

所以不起作用的代码是:

dependencies {
    implementation fileTree(dir: new File(buildDir, 'libs'), include: '*.jar')
    implementation "com.android.support:support-annotations:${supportLibVersion}"
    implementation 'com.android.support:support-v4:25.3.1'
    implementation ("com.serenegiant:common:${commonLibVersion}") {
        exclude module: 'support-v4'
    }
}

当我返回旧代码时,它可以工作:

dependencies {
    compile fileTree(dir: new File(buildDir, 'libs'), include: '*.jar')
    compile "com.android.support:support-annotations:${supportLibVersion}"
    compile 'com.android.support:support-v4:25.3.1'
    compile ("com.serenegiant:common:${commonLibVersion}") {
        exclude module: 'support-v4'
    }
}

如果有人能通过一点解释以正确的方式解决它,我真的很感激。

谢谢!

更新:

我找到了正确的解决方案,但仍然感谢您解释为什么它有效:

dependencies {
    implementation fileTree(dir: new File(buildDir, 'libs'), include: '*.jar')
    implementation "com.android.support:support-annotations:${supportLibVersion}"
    api 'com.android.support:support-v4:25.3.1'
    api("com.serenegiant:common:${commonLibVersion}") {
        exclude module: 'support-v4'
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-04
    • 1970-01-01
    • 2015-06-14
    相关资源
    最近更新 更多