当前位置: 首页 > 知识库问答 >
问题:

`android:exported需要显式地为`指定,即使我已经指定了它

曹钊
2023-03-14

我正在试用djisdk,并遵循本教程,学习如何将SDK集成到我创建的androidstudio项目中。我已经复制了所有文件的名称,唯一的区别是我在MainActivity中添加了所需的导入语句。java

当我尝试构建项目时,出现以下错误:

> Task :app:processDebugMainManifest FAILED
[path to projects]\AndroidStudioProjects\ImportSDKDemo\app\src\main\AndroidManifest.xml Error:
    android:exported needs to be explicitly specified for <activity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.


Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed : android:exported needs to be explicitly specified for <activity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

我不知道如何修理它。这里提到的一个解决方案是减少minSdk,但是我的minSdk属性已经设置为19。

任何帮助都将不胜感激。

MApplication的代码。javamain活动。java可以在本教程中找到。以下是一些其他文件:

Androidanifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.dji.importSDKDemo">
    <!-- Permissions and features -->
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-feature
        android:name="android.hardware.usb.host"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.usb.accessory"
        android:required="true" />

    <application
        android:name=".MApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.ImportSDKDemo">
        <!-- DJI SDK -->
        <uses-library android:name="com.android.future.usb.accessory" />
        <meta-data
            android:name="com.dji.sdk.API_KEY"
            android:value="f114adf2dd1d12a008e3184d" />
        <activity
            android:name="dji.sdk.sdkmanager.DJIAoaControllerActivity"
            android:theme="@android:style/Theme.Translucent"
            android:exported="true">
            <intent-filter>
                <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
            </intent-filter>
            <meta-data
                android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
                android:resource="@xml/accessory_filter" />
        </activity>
        <service android:name="dji.sdk.sdkmanager.DJIGlobalService">
        </service>

        <activity
            android:name=".MainActivity"
            android:configChanges="orientation"
            android:screenOrientation="portrait"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

建筑gradle(:app)

plugins {
    id 'com.android.application'
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.dji.importSDKDemo"
        minSdk 19
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

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

    packagingOptions{
        doNotStrip "*/*/libdjivideo.so"
        doNotStrip "*/*/libSDKRelativeJNI.so"
        doNotStrip "*/*/libFlyForbid.so"
        doNotStrip "*/*/libduml_vision_bokeh.so"
        doNotStrip "*/*/libyuv2.so"
        doNotStrip "*/*/libGroudStation.so"
        doNotStrip "*/*/libFRCorkscrew.so"
        doNotStrip "*/*/libUpgradeVerify.so"
        doNotStrip "*/*/libFR.so"
        doNotStrip "*/*/libDJIFlySafeCore.so"
        doNotStrip "*/*/libdjifs_jni.so"
        doNotStrip "*/*/libsfjni.so"
        exclude 'META-INF/rxjava.properties'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation ('com.dji:dji-sdk:4.12')
    compileOnly ('com.dji:dji-sdk-provided:4.12')

共有2个答案

范俊逸
2023-03-14

Android:导出需要设置的活动与意图过滤器

章远航
2023-03-14

除了android:exported=“true”

需要为显式指定post-android:exported。针对Android 12和更高版本的应用程序需要指定还需要tools:node=“merge”或可能tools:node=“replace”

查看有关检查合并清单并查找冲突的Android文档

我还认为您需要xmlns:工具="http://schemas.android.com/tools"属性在您的清单XML标记中,如合并规则标记中所述

 类似资料:
  • 我已经探索了很多,我发现在所有活动中,我们需要指定android:导出参数。我已经在清单中的所有活动中添加了参数,但我仍然收到此错误。 清单合并失败:android:需要为显式指定导出

  • 我正在从SDK版本30移动到31,并在意向过滤器中添加了android:exported,但仍然出现以下错误: 合并错误:Error:android:exported需要为显式指定。当相应组件定义了意图过滤器时,针对Android 12及更高版本的应用程序需要为指定一个显式值。看见https://developer.android.com/guide/topics/manifest/activit

  • 我已经检查了清单中的所有活动。xml文件中,所有活动都存在android:exported=“true”,但它始终显示此错误**清单合并失败:需要为元素显式指定android:exported 我的清单文件是 Gradle构建 等待早期响应

  • 当我从升级到时,我收到了这个错误。 错误 清单合并失败:android:导出需要显式指定。当相应组件定义了意图过滤器时,面向Android 12及更高版本的应用需要为指定显式值。有关详细信息,请参阅https://developer.android.com/guide/topics/manifest/activity-element#exported。

  • 当我将目标和编译SDK版本从30更改为31时,我得到一个错误。类似于这个问题,但没有答案。 错误:android:导出需要显式指定。针对Android 12及更高版本的应用程序需要指定一个显式值为时,相应的组件定义了一个意图过滤器。详见https://developer.android.com/guide/topics/manifest/activity-element#exported。 但是,

  • 当我更改目标并将SDK版本从30编译为31时,我得到了一个错误。类似于这个问题,但它没有答案。 错误:android:exported需要为显式指定。当相应的组件定义了意图过滤器时,针对Android 12和更高版本的应用需要为< code>android:exported指定一个显式值。详见https://developer . Android . com/guide/topics/manife

  • 问题内容: java.lang.ClassNotFoundException:com.hazelcast.core.Hazelcast 不过,这有点奇怪,因为我在运行Java时已将hazelcast-1.8.5.jar添加到类路径中: 所以我不明白为什么当hazelcast jar确实存在并且在命令行中指定时,为什么会出现ClassNotFoundException。有什么想法吗? 顺便说一句,榛

  • 如果我有这两个功能 什么时候会返回错误并且条形图是正确的函数标题?我很困惑,为什么我要明确地宣布一生: “a”读取“生命周期a”。从技术上讲,每个引用都有一些与之相关的生存期,但编译器允许您在常见情况下省略它们。 我知道什么是生命周期,但明确指定生命周期对我有什么作用?作为参考,我用铁锈书作为阅读材料