Is gradle tools:selector for permissions works ever? - android

I have a project in Android Studio with two modules, say it Module1 and Module2 with dinamic generation a lot of product flavors using configuration files. Module2 is library linked to Module1. Also I have compiled third-party library (AltBeacons). 3rd-party lib declares permissions for BLUETOOTH and BLUETOOTH_ADMIN, but I d't want to use features that need these permissions in every flavor (only for one exactly) and can't move out lib from depenencies because of my Application inheritor uses it and appear as parent for another class that used in all flavors. So, I can fetch permissions from configuration files and declare them in Module2 manifest to merge later, but 3rd party library provides its permissions in all cases. I tried merge attributes but no luck. Here's my main manifest part where I tried to resolve the problem:
<uses-permission
android:name="android.permission.BLUETOOTH"
tools:node="remove"
tools:selector="org.altbeacon.beacon" />
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN"
tools:node="remove"
tools:selector="org.altbeacon.beacon" />
, where 'org.altbeacon.beacon' is 3-rd party package.
Resulting manifest includes permissions in all cases. If remove 'tools:selector' declaration, then specified permissions not came from all libs, but I need they if fetched from my Module2. Please, help me!

Related

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.

Android: Find out which third party library is requesting a permission?

One of my projects has multiple third party libraries and one of those libraries is requesting a permission that I don't have defined in my Manifest. How can I find out which of the libraries is requesting the permission?
If I perform the command:
adb shell dumpsys package [mypackagename]
then I see the permission as "requested", but as I mentioned it doesn't exist in my project. There are a lot of third party libraries.
you can find your final permission in merged manifest file at
app/build/intermediates/manifests/full/debug/AndroidManifest.xml
You can get rid of this with
Just declare the incriminated permission in your main Manifest with the
tools:node="remove"
like:
<uses-permission android:name=”android.permission.RECORD_AUDIO” tools:node=”remove” />
Even if another third party library is asking for this specific permission, the build will be forced to not merge it in your final Manifest file.

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

Lanuch Activity located inside a jar file

I saw many posts related to that topic but still with no clear answer,
I want my activity to be compresses as a jar file and than launch one of the activities from this jar file from another application using startActivity.
i've already created a jar and imported it to the bin folder of the application (tried also add the jar at the build path but still can't launch any activity).the problem with it located on bin folder two manifest files one for the application and another for the jar file
is there a solution for that and can it be done at all?
Just add the activity definition to your application's manifest.
android will not look at the manifest located in the jar.
All activities, services, broadcast receivers and permissions that you use and are defined in the jar need to be declared in your manifest.
EDIT
Also note that an easier solution would be to make the code you have in the jar to an Android library project, this way android will take care of the manifest and the releveant UI resources that you would use (layouts, drawables etc...)
you absolutely HAVE to define the activity in the manifest of the app that is compiled. The other manifests do not contribute to the finished app at all.
Same is true for all required libraries, phone features and rights definitions.
A typical library manifest that I use looks like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.meredrica.example.library"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17"/>
</manifest>

Applications manifest and librarys manifest in Android

I'm developing an application, with another project as my library.
What properties are merged in the manifest files?
Example - If the permissions are already specified in the Library's manifest file, do they need to be specified again in the applications manifest?
Also, if there is a service in the Library project, do I need to specify again manually in the Applications manifest too (additional to library's manifest).
Thanks
There is a section of this page: http://developer.android.com/tools/projects/projects-eclipse.html#SettingUpLibraryProject that says you must (re)declare all of the bits of the library project that your application will be using in the manifest file.
Declaring library components in the manifest file
In the manifest file of the application project, you must add
declarations of all components that the application will use that are
imported from a library project. For example, you must declare activity, service, receiver, provider, and so on, as well as permission, uses-library, and similar elements.
Declarations should reference the library components by their
fully-qualified package names, where appropriate.
Personally, this seems redundant, but it may be because the app doesn't need to use all of the components of the library project, and the app shouldn't assume it will.

Categories

Resources