androidTestImplementation doesn't include Library permissions - android

In my project, I have an app module with instrumentation tests.
They use code from a library module which needs additional permissions that should normally not be included in the app. (WRITE_EXTERNAL_STORAGE)
I have put the permission in the libraries manifest and included it in the apps build.gradle using androidTestImplementation.
Unfortunately when I run the test it fails because the manifest of the installed application does not contain the required permission.
I also tried writing to context.filesDir since that should not require any permission, but it also fails with "Permission denied"
How can my library code write to the file system without the app module manifest having to include the permission?

Related

Android - How should you manage multiple modules? Manifests, grades, etc.

I understand this question is vague, but can someone outline the rules and/or how we should be dealing with multiple modules?
I've been trying to separate my app out into a base feature module, application module and instant app module.
However I've been having a nightmare building it.
I've tried searching online but there isn't really much documentation in it?
Ive got two activities in my base module manifest, as I want these in both my installed and instant app. Do I then need to copy these activity manifest entries into my other manifests? I tried running my installed apk without adding in these activities (I thought it might pull it from the base module) but then android studio says can't find default activity to launch the application with. So I need to copy the activity entries into all manifests?
I've also got manifest entry conflicts from all the libraries I'm using. FacebookInitProvider , FacebookInitProvider, CrashlyticsInitProvider etc. I don't have these entries in any manifest, they are adding themselves in to every manifest causing merge conflicts when building.
With the build grades, I've put in the base just the libraries necessary to run the base / instant app (to keep it as small as possible). The installed gradle then has all the extra libraries for the full sized application. If I use
implementation project(":base")
Will it automatically pull in all the dependencies that base uses? Or do I need to redeclare these?
I ask because after getting the app to build, firebase and firestore was causing an exception on getting the instance with the message "Firestore module not found" which makes it look like it hasn't pulled in the dependencies properly?
I apologise for the lengthy post, but I'm honestly at the end of my tether here. Truly stuck!
Im not sure I understand all your project structure correctly so I will give you general information on an app with modules:
Lets say you have the application called "appone" and have a module called "moduleone"
In the module gradle file you declare the minimum you need for the module to work properly by itself and in the manifest just configuration specific for the module that will not be required to be defined in the appone manifest.
Now in the appone manifest, this is the main file, you will have to set here the activity declarations and app permissions (not in moduleone), android studio merges the two files automatically so when you compile it will make one manifest file with both manifests contents so this is what can make conflicts if you declare the same or conflicting data on both files.
In the appone build.gradle file this is where you declare the implementation project(':moduleone'), and the implementation of libraries required by appone.
If for example moduleone uses firebase library and in appone you also directly require access to the firebase library you could declare it in both build.gradle files, you just need to make sure both use the same version.
Also you will need to declare moduleone on the settings.gradle file using: include ':moduleone'
appone is declared as an com.android.application and moduleone is declared as com.android.library.
Also appone has in its manifest an activity declared with the LAUNCHER category.

Correct way to use <uses- library> to create module that depend on an external JAR library

In this page: https://developer.android.com/studio/projects/android-library.html#Considerations
It states that:
You can develop a library module that depends on an external library. (for example, the Maps external library). In this case, the dependent app must build against a target that includes the external library (for example, the Google APIs Add-On). Note also that both the library module and the dependent app must declare the external library in their manifest files, in a element.
So I tried to do what the paragraph says above.
1- I created a module that has this in its gradle:
compile 'com.twitter.sdk.android:twitter-core:3.0.0'
compile 'com.twitter.sdk.android:tweet-ui:3.0.0'
2- and I added this in my manifest.xml
<uses-library
android:name="com.twitter.sdk"
android:required="true"/>
3- I imported my .aar file to my main app.
4- I added the same code into my main app manifest.xml
<uses-library
android:name="com.twitter.sdk"
android:required="true"/>
But of-course it shows an error:
Delete <uses-library> from your manifest. It it only for cases where you are trying to use a "library" that is part of a device's firmware. The "Maps" example that they cite is from the long-obsolete Google Maps V1 for Android implementation.
I am not aware of any device manufacturer that has advised its developers to add <uses-library> elements to their manifest for com.twitter.sdk.

Getting all Permissions from APK, Android 6

With Android 6's dynamic permissions, is it possible to get all the permissions an APK requires from a compiled apk?
The problem is that in our project, we sometimes add third party libraries to our project, and sometimes they require more permissions than our app initially required. I would like to be able to detect such situations at the CI build stage.
"Dynamic permissions" (a.k.a., runtime permissions) do not change anything. They all still have <uses-permission> elements in the manifest. aapt dump permissions, or reading in the merged manifest, will tell you what is requested by your current manifest.
This does not help with libraries that do not publish a manifest in their AARs that contain the <uses-permission> elements required by the library. Hopefully, the authors of such a library document what they are expecting and you are adding the <uses-permission> elements to your own manifest.

Location of a permission

I am making an AAR for licensing functionality. I plan to use it in multiple applications.
As per documentation, licensing implementation needs a permission in manifest file: "com.android.vending.CHECK_LICENSE"
I am not sure where should this permission be kept,in application's manifest file or library project's manifest file.
All your library related permissions/metadata/activities relevant info should be declared in your library manifest file

Expansion files at Android 6

On Android 6 devices, we've noticed that expansion files now need that we request the WRITE_EXTERNAL_STORAGE permission at runtime, which allows the user to deny, which doesn't allow us to continue with the app startup.
Is there a way to prevent the expansion files to use the WRITE_EXTERNAL_STORAGE or to prevent the user of denying?
If that request must appear when using expansion files, how are we supposed to handle that gracefully?
I also have this problem. To resolve it for API 23 I download .obb file to private app's file directory instead of obb directory which my app hasn't access to. You can review my solution here .
Usage:
repositories {
maven { url 'https://dl.bintray.com/alexeydanilov/apk-expansion' }
}
dependencies {
compile 'com.danikula.expansion:expansion:VERSION#aar'
compile 'com.danikula.expansion:license:VERSION#aar'
compile 'com.danikula.expansion:zip:VERSION#aar'
}
See the latest versions here.
Seems to be a bug on Android 6.0
https://code.google.com/p/android/issues/detail?id=197287

Categories

Resources