【问题标题】:Class referenced in the manifest, ..., was not found in the project or the libraries在项目或库中找不到清单中引用的类...
【发布时间】:2022-01-04 15:41:25
【问题描述】:

以前有人问过这个问题,但在我的情况下,提供的解决方案似乎都没有用,除了抑制错误,这似乎很不雅。

我在应用程序中的所有活动都看到此错误,但活动都在那里并且可以在项目工具窗口中看到,并且应用程序编译和运行没有任何问题:只是错误消息是错误的。

我尝试在类名前面插入完整的包名,但没有帮助,我尝试使缓存无效并重新启动,这也没有帮助还是不行。。包名在所有类文件中都正确声明了,活动都是public

这是我的 AndroidManifest.xml:-

<?xml version="1.0" encoding="utf-8"?>
<!--
   Copyright © 2021. Richard P. Parkins, M. A.
   Released under GPL V3 or later
  -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="uk.co.yahoo.p1rpp.secondsclock">

    <uses-permission android:name="com.android.alarm.permission.SET_ALARM" />

    <application
        android:theme="@style/Theme.MaterialComponents.DayNight"
        android:allowBackup="true"
        android:fullBackupOnly="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_label"
        android:supportsRtl="true">

        <receiver
            android:name=".SecondsClockWidget"
            android:exported="true">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/seconds_clock_widget_info" />
        </receiver>

        <activity
            android:name=".ClockActivity"
            android:screenOrientation="fullSensor"
            android:exported="false">
            <intent-filter>
                <action android:name="uk.co.yahoo.p1rpp.ClockActivity" />
            </intent-filter>
        </activity>

        <activity
            android:name=".ClockConfigureActivity"
            android:screenOrientation="fullSensor"
            android:exported="false">
            <intent-filter>
                <action android:name="uk.co.yahoo.p1rpp.ClockConfigureActivity" />
            </intent-filter>
        </activity>

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_label"
            android:screenOrientation="fullSensor">
            <intent-filter>
                <action android:name="uk.co.yahoo.p1rpp.MainActivity" />
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".WidgetConfigureActivity"
            android:screenOrientation="fullSensor"
            android:exported="false">
            <intent-filter>
                <action android:name="uk.co.yahoo.p1rpp.WidgetConfigureActivity" />
            </intent-filter>
        </activity>

        <meta-data
            android:name="com.samsung.android.icon_container.has_icon_container"
            android:value="true"/>
    </application>

</manifest>

进一步看,错误消息似乎是由我最近在build.gradle 中使用显式sourceSets 所做的更改引发的,如下所示:-

    sourceSets {
        release {
            res.srcDirs = ['src/main/java/uk/co/yahoo/p1rpp/secondsclock']
        }
        debug {
            res.srcDirs = ['src/main/java/uk/co/yahoo/p1rpp/secondsclock']
        }
        withlater {
            res.srcDirs = ['src/main/assets/ForLater/',
                           'src/main/java/uk/co/yahoo/p1rpp/secondsclock']
        }
    }

[这是我对Android gradle build: excluded java source files get compiled的回答]

如果我取出那段代码,我不会收到错误消息,但是为什么它实际上没有错误消息时报告错误。即使实际的 gradle 构建正确地理解了它们,看起来对缺失类的检查可能没有正确解释显式 sourceSets。

【问题讨论】:

    标签: android-studio android-gradle-plugin


    【解决方案1】:

    此更改修复了清单中的错误消息:-

        sourceSets {
            release {
                //res.srcDirs = ['src/main/java/uk/co/yahoo/p1rpp/secondsclock']
            }
            debug {
                //res.srcDirs = ['src/main/java/uk/co/yahoo/p1rpp/secondsclock']
            }
            withlater {
                res.srcDirs = ['src/main/assets/ForLater/',
                               'src/main/java/uk/co/yahoo/p1rpp/secondsclock']
            }
        }
    

    如果我没有明确指定res.srcDirs,它会使用默认值并查找活动类。但是src/main/assets/ForLater 中的代码不会被检查错误。

    【讨论】:

      猜你喜欢
      • 2015-02-16
      • 2021-01-27
      • 2022-11-15
      • 1970-01-01
      • 1970-01-01
      • 2021-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多