I have the same issue mentioned in this post AndroidTest Manifest permission not detected
and this post AndroidManifest in androidTest directory being ignored
--> If I put the test manifest in androidTest, debugAndroidTest, androidTestDebug, it never gets picked up and merged.
the answers about putting the AndroidManifest.xml in the debug folder are correct; that does seem to work. (put the test manifest in src/debug
What I want to know is why can't you put it in the androidTest directory? All the documentation I've read while trying to figure this out makes it sound like you should be able to, and that if you can't then I'm thinking that sounds like some bug in the manifest merger.
For what it's worth, I'm using Android Studio
That is correct and totally agree with you on the confusing documentation. The AndroidManifest.xml under androidTest* source sets would be packaged for the instrumentation APK that does your tests on your actual app APK. If you open the generated APKs for debug and androidTest under build/outputs/apk/ after compiling your app module with the command gradlew assembleDebugAndroidTest (assuming that you haven't changed the testBuildType in you build.gradle, more info here), you'll find that any AndroidManifest.xml configuration added under androidTest will be in the androidTest APK and not in your debug app APK.
And also as you said, in case you need test specific configurations like extra permissions, you'll have to place them in the AndroidManifest.xml under the debug source set instead of main, hence they'll only be available for testing your app but not in your release build. Of course you can always double check by opening the generated APKs after compiling to make sure that the configuration is right for each build variant.
If you need to add extra permissions for tests, you can do it.
You should set the same android:sharedUserId in default AndroidManifest.xml and androidTest/AndroidManifest.xml.
For example:
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"
android:sharedUserId="com.yourpackagename.uid">
<application
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:replace="android:allowBackup">
</application>
</manifest>
androidTest/AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:sharedUserId="com.yourpackagename.uid">
<uses-permission android:name="android.permission.***" />
</manifest>
For details: https://stackoverflow.com/a/14196493/3901000
Related
I have a complex AndroidManifest.xml, which contains a receiver:
<receiver android:name=com.my.package.ApplicationBroadcastReceiver>
I want to create an AndroidManifest.xml for the debug version of my app.
I placed that under debug/AndroidManifest.xml. The only difference in the debug manifest is that I am using another receiver:
<receiver android:name=com.my.package.DebugApplicationBroadcastReceiver>
For now, I copied AndroidManifest.xml into debug/AndroidManifest.xml and just changed that line. After reading this page about merge rules, I specified this rule at the top of my debug/AndroidManifest.xml file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.my.package"
android:versionCode="1"
android:versionName="1.0"
tools:node="replace">
However, when building I am getting this error:
Manifest merger failed : Attribute manifest#versionCode value=(1) from AndroidManifest.xml:5
is also present at AndroidManifest.xml:5
Attributes of <manifest> elements are not merged.
So even though I specified tools:node="replace" in the manifest tag, merging still fails.
My question has two parts:
A.How can I make the merging work?
B.Since the difference between AndroidManifest.xml and debug/AndroidManifest.xml is just one line, how can I just specify the line that is overriden instead of copying the whole file?
Based on your error message, you need something like this:
tools:replace="android:versionCode"
I'm working on my first android app, and I'm just getting started with product flavors. I have a free version in beta, and I'm starting to make a a paid version. I'm a bit confused about the manifests.
The paid version will have one activity that the free version does not, and the two will have different permissions. I'm thinking that I will remove the permissions from the main manifest, that the free manifest will have nothing in it but its permissions, and the paid manifest will have nothing in it but its permissions and the extra activity.
For example, the free manifest might be
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app">
<uses-permission android:name="android.permission.INTERNET"/>
</uses-permission>
</manifest>
Is this correct?
That's correct, however, I would recommend you put all common Manifest information in the main, as CommonsWare mentioned.
Also, as a tip, if you do need to replace a value in the main Manifest for any reason (debugging for example), I would use the tools:replace tag like so:
Free flavor:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example">
<application
android:name=".FreeApp"
android:allowBackup="false"
tools:replace="allowBackup,name"/>
</manifest>
This would replace the tags name and allowBackup from main with what you have in this manifest.
I recommend you check out the following link for more information about flavoring and variants, in case you haven't already:
https://developer.android.com/studio/build/build-variants.html
I'm trying to create bindings for Zendesk library and I faced with a problem.
Zendesk Belvedere library (belvedere-1.0.2.1.aar) contains a file provider in its manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
...
<application>
<provider
android:name="com.zendesk.belvedere.BelvedereFileProvider"
android:authorities="${applicationId}.belvedere.attachments"
android:exported="false"
android:grantUriPermissions="true" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/belvedere_attachment_storage" />
</provider>
</application>
</manifest>
When Gradle is used as build tool, it puts this aar to the APK file and it replaces ${applicationId}.belvedere.attachments with com.your_package_name_here.belvedere.attachments in the merged manifest file. It's fine.
However, Xamarin handles it differently. Here is what I found in the manifest of my final APK:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
...
<application
...
...
<provider
android:name="com.zendesk.belvedere.BelvedereFileProvider"
android:exported="false"
android:authorities="dollar_openBracket_applicationId_closeBracket"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/belvedere_attachment_storage" />
</provider>
...
...
</application>
</manifest>
Obviously, dollar_openBracket_applicationId_closeBracket is not what I need.
Seems everything works, however it makes impossible to install several Xamarin applications that use these bindings, because all of them would have conflicting providers with the same authority (and user would get INSTALL_FAILED_CONFLICTING_PROVIDER error).
Is there a way to change dollar_openBracket_applicationId_closeBracket in the manifest?
Edit: A small sample that shows the problem: https://gitlab.com/lassana/ZendeskXamarin/
The current Xamarin.Android manifest merge build task, up to and including
version 7.1.0.19, does not provide any bundeID/ApplicationID (${}} substitution in the merged manifest like gradle does.
This is just a limitation in the manifest processing/merge task, thus you are ending up with dollar_openBracket_applicationId_closeBracket in your final manifest and will have to correct both manifests yourself.
The only current solution know to me to avoid the manifest merge task and it's limitation is to:
Remove the file provider entry from the '.aar`'s manifest
Add the complete file provider entry your app's manifest
Note: You have to do both steps
Depending upon how often the .aar is changing and where you are sourcing the .aar file from:
Manually unzip the aar, remove the entry and re-zip the aar (the quickest way)
Automated this in a build step via a shell script using bash or powershell cmds
Write a MSBuild C#-based Task to do it.
Request that the aar manifest be changed upstream (not likely to happen ;-) since it works fine w/ gradle)
FYI: Personally I have seen the ${applicationId} issue you are having a few times. I have written build scripts (bash/.ps1) to do the manifest fix-up as it seems to always be some special case in the .arr's manifest that I am dealing with.
According to Microsoft team, Xamarin.Build.Download (0.4.12-preview) finally fixes this bug.
So, you should follow these steps:
Update the Nuget Package to 0.4.12-preview3
Restart the IDE
Delete all cached locations of NuGet Packages
Delete bin/obj
Rebuild
The main manifest file of your project is the higher priority manifest, so if you add the provider element to main manifest file and apply a merge rule marker for android:authorities attribute, the merger tools replaces the android:authorities value that you declare in the main manifest.
Declare provider element in main manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
...
...
<application>
<provider
android:name="com.zendesk.belvedere.BelvedereFileProvider"
android:authorities="com.example.belvedere.attachments"
tools:replace=”android:authorities” >
</provider>
</application>
I have an android Library that outputs an aar library. This library will be built into different projectFlavors of Mobile, TV and Wear apps. I think that each of these platforms' should be the ones that set variables like the app name, icon, and permissions through the manifest and productflavors.
Is there any way to build an AAR without requiring an AndroidManifest.xml and therefore drawables(for the icon)?
More information about what I'm doing can be found at my last question on the subject:
Android Studio Java Library Module vs. Android Library Module
Any android library needs to have an AndroidManifest.xml file, but a name or an icon is not required. It's only needed when there is an activity that is MAIN and LAUNCHER.
You simply could use this manifest and your library will work like a charm.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="[your package]"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="[min supported version]" />
<application/>
</manifest>
You can go with the AndroidManifest.xml below if you don't need to setup any Android component like Activities or Services or add custom properties.
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.your.library.base.package" />
I've just started trying to set up some unit testing in what is essentially my first android app. I've had a hell of a time finding resource for this, but ultimately was able to scrape together what I hoped was the right path forward.
First, this is what I've done.
In Eclipse, I right-clicked my project that I'd like to create a test project for.
I selected AndroidTools -> New Test Project
I filled out the necessary information selecting a location of ../MyApp/tests for the new project and selected MyApp as the project to test. Everything else was left as default.
While this was executing I received the below as an error:
[2011-04-01 08:13:02 - WPMSTest] R.java was modified manually! Reverting to generated version!
But everything seemed okay. I had a new source tree in my tests folder.
So I tried to execute it (first on hardware, then on the emulator) by RunAs -> Android jUnit test.
In both runs I received the below in my eclipse console:
[2011-04-01 08:23:04 - WPMSTest] Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554[2011-04-01 08:23:04 - WPMSTest] Failed to launch test
My two manifest files:
WPMSTest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.WPMS.test"
android:versionCode="1"
android:versionName="1.0">
<instrumentation android:targetPackage="com.WPMS" android:name="android.test.InstrumentationTestRunner" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<uses-library android:name="android.test.runner" />
</application>
WPMS:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.WPMS"
android:versionCode="1"
android:versionName="1.0">
<application android:label="#string/app_name" android:icon="#drawable/ic_launcher_wpms">
<activity android:name=".WPMS"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
I'm hoping someone has seen something like this before and can shed some light on what I'm doing wrong. Please let me know if you need any more files and I'll be sure to post them.
Thanks!
I was missing a TestSuite in my Test Project. Once I had my AllTests class extend TestSuite I got past the error.
For me the problem was that I was using JUnit 4. When I changed to JUnit 3 it started working. I hope this helps.
[2011-04-01 08:13:02 - WPMSTest] R.java was modified manually! Reverting to generated version!
You get this error when you manually make changes in the R.java file. At times, when you clean the project, R.java file goes missing. At such occasion you must either copy the same program's R.java(if stored somewhere as a copy) or create an entire new project.
For your second issue, I too have got similar error when I was testing my app on the device. I had to make changes in the shell using $adb. then the device got recognised.
I had the same problem: JUnit 3 TestCase works, but when running JUnit 4 TestCase, I got "Failed to launch test" error.
But after following Ken's suggestion, i.e. make the JUnit 4 test class extends TestCase, and rename the test method with the "test" prefix, the test launches and runs the test!