【问题标题】:android:exported needs to be explicitly specified after add SonarQube in build.gradleandroid:exported 需要在 build.gradle 中添加 SonarQube 后显式指定
【发布时间】:2022-01-17 05:33:53
【问题描述】:

我在 Android Studio 中创建了一个简单的 Hello World 项目,作为 Jenkins 管道中的示例,它可以工作,但我想添加 SonarQube 分析,因此我在 build.gradle 中添加了后续行,如文档所示 (https://plugins.gradle.org/plugin/org.sonarqube)

buildscript {
    repositories {
        google()
        mavenCentral()
        maven {
          url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.3"
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.3"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

apply plugin: "org.sonarqube"

task clean(type: Delete) {
    delete rootProject.buildDir
}

我可以毫无问题地使用./gradle build 构建,但是当我执行./gradlew sonarqube 时出现以下错误:

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

我调查并检查了我的/app/src/main/AndroidManifest.xml 中是否有android:exported="true or false",并且确实如此。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.holapromad">

    <application
        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.HolaPromad">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

是错误还是什么?谢谢

【问题讨论】:

    标签: android-studio gradle sonarqube


    【解决方案1】:

    不确定是否也是您的情况:在我的项目中,问题是由 Manifest 合并任务的 AndroidTest 变体引起的,该变体使用了 androidx.test.ext:junit 库的过时版本。

    只需将此库更新到我的应用程序 build.gradle 文件中的最新版本(当前为 1.1.3),即可解决问题。

    【讨论】:

      猜你喜欢
      • 2022-07-13
      • 1970-01-01
      • 2022-09-23
      • 2022-09-29
      • 2021-11-28
      • 2022-08-12
      • 2022-01-21
      • 2021-10-03
      • 2022-07-27
      相关资源
      最近更新 更多