Android:导出需要显式指定 <service>。面向 Android 12 及更高版本的应用



有一个错误android:exported需要在编译

时明确指定servicegradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-7.3-bin.zip

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.nari.vpn">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="com.android.vending.BILLING" />
<application
android:name="com.nari.vpn.MainApplication"
android:allowBackup="true"
android:exported="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning"
tools:targetApi="n">
<activity
android:name="com.nari.vpn.activity.SplashActivity"
android:exported="true"
android:theme="@style/splashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.nari.vpn.activity.About" android:exported="true" />
<activity android:name="com.nari.vpn.activity.Faq" android:exported="true"/> <!-- google ads -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="@string/admob_app_id" />
<meta-data
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true" />
<activity android:name="com.nari.vpn.activity.MainActivity" android:exported="true"
android:launchMode="singleTask"
/>
</application>
</manifest>

我指定android:exported=为所有的活动,但它仍然给我一个错误。在Java代码中没有错误被报告为错误。

编辑:

依赖/库使用:

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.github.AnchorFreePartner.hydra-sdk-android:sdk:3.4.0'
implementation 'com.github.AnchorFreePartner.hydra-sdk-android:openvpn:3.4.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'com.google.android.material:material:1.5.0-alpha01'
implementation 'com.jakewharton:butterknife:10.2.3'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
implementation 'androidx.multidex:multidex:2.0.1'
//cutoms things
//implementation "com.airbnb.android:lottie:3.6.0"

//ad-mob and facebook mediation
implementation 'com.google.android.gms:play-services-ads:20.2.0'//19.8.0
implementation 'com.google.ads.mediation:facebook:6.5.1.0'
//customs
implementation 'com.github.pepperonas:materialdialog:0.3.4'
implementation 'pl.bclogic:pulsator4droid:1.0.3'
//Preference Library
implementation 'com.pixplicity.easyprefs:library:1.9.0'

//Drawer Library
implementation 'com.infideap.drawerbehavior:drawer-behavior:1.0.1'
//checkBox
implementation 'net.igenius:customcheckbox:1.3'

//Custom Toast
implementation 'com.github.GrenderG:Toasty:1.5.0'
}

2]更新了所有依赖项仍然不能工作

原因是你使用的一些依赖库的元素没有"android:exported"属性。

你需要这样做:

将gradle中的版本降低到30,然后同步并构建。进入你的AndroidManifest.xml文件,点击"合并清单"。查找Activity, Receiver, Service等没有"android:exported"属性。然后按这种方式将它们添加到AndroidManifest.xml文件中。

<activity
android:name="SomeActivity"
android:exported="false"
tools:node="merge"
tools:replace="android:exported" />

现在你可以把你的版本增加到31。

我把它修复了!希望对你有帮助!

相关内容

最新更新