ServiceNotDeclaredException: BeaconService is not properly declared in AndroidManifest.xml
I am getting the following error when running Unit Test in my Android project (I am not getting an error when building the app and running it on the device):
BeaconService is not properly declared in AndroidManifest.xml. If you are using Eclipse make sure your project.properties has manifestmerger.enabled = true org.altbeacon.beacon.BeaconManager $ ServiceNotDeclaredException: BeaconService is not being declared properly in AndroidManifest.xml. If you are using Eclipse make sure your project.properties has manifestmerger.enabled = true
Android Studio automatically merges AndroidManifest.xml from Android Beacon Library into my own AndroidManifest.xml, making it unnecessary to declare Beacon services in my AndroidManifest.xml.
This is my current AndroidManifest.xml (located in my / src / main / folder, I don't have it in the / src / test / folder):
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.xxx.xxx">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<permission
android:name="com.xxx.xxx.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.xxx.xxx.permission.C2D_MESSAGE" />
<application
android:name=".xxxApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:label="@string/title_activity_login" />
<receiver
android:name="org.jboss.aerogear.android.unifiedpush.gcm.AeroGearGCMMessageReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.xxx.xxx.android.test.xxxApp" />
</intent-filter>
<meta-data
android:name="DEFAULT_MESSAGE_HANDLER_KEY"
android:value="com.xxx.xxx.push.AGMessageListener" />
</receiver>
</application>
</manifest>
I already looked at my manifest-merger-release-report.txt file inside my build folder (app / build / output / apk / manifest-merger-release-report.txt) but couldn't find any problems.
This is the part that contains Android Beacon Library:
uses-permission#android.permission.BLUETOOTH
ADDED from org.altbeacon:android-beacon-library:2.1.3:11:5
android:name
ADDED from org.altbeacon:android-beacon-library:2.1.3:11:22
uses-permission#android.permission.BLUETOOTH_ADMIN
ADDED from org.altbeacon:android-beacon-library:2.1.3:12:5
android:name
ADDED from org.altbeacon:android-beacon-library:2.1.3:12:22
uses-permission#android.permission.RECEIVE_BOOT_COMPLETED
ADDED from org.altbeacon:android-beacon-library:2.1.3:13:5
android:name
ADDED from org.altbeacon:android-beacon-library:2.1.3:13:22
receiver#org.altbeacon.beacon.startup.StartupBroadcastReceiver
ADDED from org.altbeacon:android-beacon-library:2.1.3:16:9
android:name
ADDED from org.altbeacon:android-beacon-library:2.1.3:16:19
intent-filter#android.intent.action.ACTION_POWER_CONNECTED+android.intent.action.ACTION_POWER_DISCONNECTED+android.intent.action.BOOT_COMPLETED
ADDED from org.altbeacon:android-beacon-library:2.1.3:17:13
action#android.intent.action.BOOT_COMPLETED
ADDED from org.altbeacon:android-beacon-library:2.1.3:18:17
android:name
ADDED from org.altbeacon:android-beacon-library:2.1.3:18:25
action#android.intent.action.ACTION_POWER_CONNECTED
ADDED from org.altbeacon:android-beacon-library:2.1.3:19:17
android:name
ADDED from org.altbeacon:android-beacon-library:2.1.3:19:25
action#android.intent.action.ACTION_POWER_DISCONNECTED
ADDED from org.altbeacon:android-beacon-library:2.1.3:20:17
android:name
ADDED from org.altbeacon:android-beacon-library:2.1.3:20:25
service#org.altbeacon.beacon.service.BeaconService
ADDED from org.altbeacon:android-beacon-library:2.1.3:24:9
android:enabled
ADDED from org.altbeacon:android-beacon-library:2.1.3:26:13
android:label
ADDED from org.altbeacon:android-beacon-library:2.1.3:29:13
android:exported
ADDED from org.altbeacon:android-beacon-library:2.1.3:27:13
android:isolatedProcess
ADDED from org.altbeacon:android-beacon-library:2.1.3:28:13
android:name
ADDED from org.altbeacon:android-beacon-library:2.1.3:25:13
service#org.altbeacon.beacon.BeaconIntentProcessor
ADDED from org.altbeacon:android-beacon-library:2.1.3:30:9
android:enabled
ADDED from org.altbeacon:android-beacon-library:2.1.3:32:13
android:exported
ADDED from org.altbeacon:android-beacon-library:2.1.3:33:13
android:name
ADDED from org.altbeacon:android-beacon-library:2.1.3:31:13
Any idea what might be causing this problem?
source to share
When using Robolectric tests with Android Beacon Library, just add this line to the beginning of the test:
BeaconManager.setsManifestCheckingDisabled(true);
This will disable validation of the correct manifest entries on instantiation BeaconManager
. This is necessary because Robolectric doesn't give you access to the real AndroidManifest when running tests. I faced the same problem myself when creating Robolectric tests inside the library itself. You can see an example of this here:
source to share