Error in configuring network security xml in android - android

In the android network security docs , it says to create a network_security_config.xml file in res/xml folder.
In order to make an entry in manifest file, it says to make an entry in this way
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application android:networkSecurityConfig="#xml/network_security_config"
... >
...
</application>
</manifest>
But I am getting the error No resource identifier found for attribute 'networkSecurityConfig' in package 'android'
I also checked for the valid attributes in application tag ( android docs ), there is no attribute as "networksecurityconfig"

You need to set your compileSdkVersion to 24 or higher and set your buildToolsVersion to 24.0.0 or higher.
With regards to the documentation, that's a documentation bug.

The documentation is fixed, the xml should live inside res/xml which is not in the root but inside android/app:
android/app/src/main/res/xml/network_security_config.xml
From minimumSDK 20 you will need the file and be sure to whitelist localhost and 10.0.2.2 and 10.0.3.2 or you'll have trouble on development

Related

React Native: Error: Package name not found

After integrating RN into an existing Android project, I get the following error:
Error: Package name not found in /home/.../AndroidManifest.xml at Object.projectConfig (/home/.../rn_integrated_app/node_modules/#react-native-community/cli-platform-android/build/config/index.js:74:11) at Object.get project [as project]
As I understand the problem is that there is no package attribute in the relevant AndroidManifest.xml file. Since my project has many flavors, the package attribute is added dynamically, while compiling, through app/build.gradle:
def pkgDataEntry = getRightValue(packagesData, variantMap)
variant.getMergedFlavor().applicationId = pkgDataEntry.pkg
So that the final merged manifest file does have the package attribute.
The error occurs here(#react-native-community/cli-platform-android/build/config/index.js):
const packageName = userConfig.packageName || getPackageName(manifest);
if (!packageName) {
throw new Error(`Package name not found in ${manifestPath}`);
}
Is there a way to make RN read the merged manifest file?
If not, how can I modify userConfig to contain the package name? I couldn`t find anything about it in the docs.
Thank you
For me, the solution was to add the "package" tag to the manifest tag.
I didn't have to create another dummy folder.
The manifest open tag now looks like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourProjectName">
If anybody encounters the same issue, when having multiple flavors and AndroidManifest.xml files,here`s my conclusion:
RN has some kind of a bug that it requires the first folder alphabetically, in android/app/src, which has AndroidManifest.xml file,to have the package attribute. Otherwise, it will throw an error.
A simple solution would be to create a dummy folder, e.g aaa (first alphabetically) and to create AndroidManifest.xml inside of it, with the following attribute - package:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="aaa"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission
android:name="android.permission.GET_ACCOUNTS"
tools:node="remove"/>
</manifest>
For me, this error start after upgrade the sdkVersion from 31 to 33 and gradle version.
I did check the changes in git, and notice that the package attribute was removed from AndroidManifest.xml.
So I did add this attribute again.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.yourpackage">

Android library with SyncAdapter not running in more than 1 app in the same phone

I am creating an Android library that uses SyncAdapter to do a small task in the background every day. This works perfectly fine if used in only one app. If the same library is used by two apps in the same phone, it gives CONFLICTING_PROVIDER error.
To fix this. I used ${applicationId} in library manifest like:
<provider
android:name=".sync.DummyProvider"
android:authorities="${applicationId}.mysdk"
android:exported="false"
android:syncable="true" />
This generates dynamic authority for the provider.
Now, the problem is that SyncAdapter needs to have contentAuthority in the xml folder.
<sync-adapter
xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="#string/sync_account_type"
android:allowParallelSyncs="false"
android:contentAuthority="<-----NOT SURE WHAT TO ADD HERE----->"
android:isAlwaysSyncable="true"
android:supportsUploading="false"
android:userVisible="false"/>
I tried android:contentAuthority="${applicationId}.mysdk" but applicationId doesn't get replaced by the app's package name. Instead, it take it as it is and gives error as:
E/ActivityThread: Failed to find provider info for ${applicationId}.mysdk
These are the step I have tried till now
Creating stringValue from build.gradle in library's build.gradle file, but here applicationId can not be used there.
Moved contentAuthority in the Manifest, as ${applicationId} works there but nothing happens after doing this. contentAuthority needs to be in the xml folder.
First you need to declare the application id in your build.gradle file
defaultConfig {
applicationId "com.my.package"
....
}
Then use the following xml for your syncAdapter
<sync-adapter
xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="#string/account_authorities"
android:accountType="#string/account_type"
android:userVisible="false"
android:supportsUploading="false"
android:allowParallelSyncs="false"
android:isAlwaysSyncable="true"/>
#pranav-agraval's answer worked.
I didn't change anything in the SDK. The string resource I was using had a key content_provider.
I would have to ask any one who is using the SDK to add this key to their string.xml file. This should be of pattern application_package_name.sdk_name.

Cannot build Linphone android with different package name

I am trying to build Linphone android from this, with SDK api 23 and NDK r11c on Ubuntu 16.10. I already built it successfully but I cannot change its package name so as to be able to upload it to Google Play Store despite following its instruction to the letter. For Example:
To create an apk with a different package name
You need to edit the custom_rules.xml file:
look for the property named "linphone.package.name" and change it value accordingly
Already done:
<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules">
<property name="linphone.package.name" value="my.name" />
....
Then I did this
also update the values in the AndroidManifest file where the comment appears
by replacing all instances of org.linphone in every <!-- Change package ! --> comment. All of them are comments though so that may be not important. I did not change this one because it will throw an error when I run make
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.linphone"
android:installLocation="auto"
android:versionCode="3253"
android:versionName="3.2.5">
And the next step is
change the package name also in the files: res/xml/syncadapter.xml, res/xml/contacts.xml and res/values/non_localizable_custom where appears
which I did exactly like I was told. The last step is running make.
But the result I always get is org.linphone no matter whichever name I changed it to. Did I botched any step? Can we even change linphone package name to something other than org.linphone? And no, I cannot change its package name by this method, it would just brick the project, render it unbuildable.
Now the package name are in build.gradle and no more in custom_rules.xml
def getPackageName() {
return "org.linphone"
}
and its used here:
defaultConfig {
compileSdkVersion 23
buildToolsVersion "25.0.2"
applicationId getPackageName()
multiDexEnabled true
}

Android Studio 6.0 merger fail

Just updated to the latest version of Android Studio and i get this error in the AndroidManifest file
Manifest merger failed : Attribute application#icon value=(#drawable/project_launcher_icon) from AndroidManifest.xml:48:9
is also present at com.github.anupcowkur:reservoir:1.1.1:6:45 value=(#drawable/ic_launcher)
Suggestion: add 'tools:replace="icon"' to element at AndroidManifest.xml:44:5 to override
I tried adding tools:replace="#drawable/ic_drawer" in my manifest but i get this error:
Error:(44, 5) tools:replace specified at line:44 for attribute tools:drawable/ic_drawer, but no new value specified
Any ideas?
Following Android Studio's suggestion and adding the following attribute tools:replace="icon" should allow it to build your app successfully, without resorting to using the old manifest merger (which isn't a very forward-looking solution indeed).
Of course, you'll first have to declare the namespace "tools" in order to use it:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.sample.app" >
You should add tools:replace="icon", just like the error message says.
Additional attributes can be replaced using the syntax tools:replace="icon,name,theme"
look here:
All markers belong to the Android tools namespace, therefore you must declare the namespace in any AndroidManifest.xml containing at least one marker :
xmlns:tools="http://schemas.android.com/tools"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.tests.flavorlib.app"
**xmlns:tools="http://schemas.android.com/tools"**>
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
**tools:replace=”icon, label”**/>
</manifest>
you should add xlms:tools and tools:replace those two lines in manifest file.
Android Studio 0.6 use the new manifest merger tool. This new merger was introduced in version 0.10 of the plugin. As of 0.11, this tool is used by default by the gradle plugin.
In order to revert to the old manifest merger, please add to your build.gradle the following configuration :
android {
useOldManifestMerger true
}
For me this worked. Try adding the code in the main module(project) manifest file:
add
xmlns:tools="http://schemas.android.com/tools" in your manifest tag
add
tools:replace="android:icon,android:label,android:theme" in your application tag
These will let Android Studio know that the icon, label and theme to be used are from that manifest and not from other projects included.

"aapt dump badging" wants minSdkVersion to be a string but "adb install" needs it as an integer

I need to have a different minSDKVersion in the Google Play Store (for device filtering purposes) than for private beta testing. I tried the following:
AndroidManifest.xml contains the following:
<manifest …>
[…]
<uses-sdk android:minSdkVersion="#integer/minSdkVersion" android:targetSdkVersion="15"/>
[…]
</manifest>
res/values/config.xml is generated by maven and contains the following:
<resources>
<integer name="minSdkVersion">8</integer>
</resources>
This works fine except for aapt dump badging which complains:
ERROR getting 'android:minSdkVersion' attribute: attribute is not a string value
Unfortunately aapt dump does not dump the rest. So I am left with no output except this error :-(
When I change the minSdkVersion reference to a string reference like this:
AndroidManifest.xml contains the following:
<manifest …>
[…]
<uses-sdk android:minSdkVersion="#string/minSdkVersion" android:targetSdkVersion="15"/>
[…]
</manifest>
res/values/config.xml is generated by maven and contains the following:
8
With this I cannot install the app because somehow my device with API Level 16 (Jelly Bean) does not allow APKs with
sdkVersion:'8'
(according to aapt dump badging) to be installed. The error is: INSTALL_FAILED_OLDER_SDK
It seems the string reference is somehow misinterpreted while creating the APK.
What can I do to have android:minSdkVersion referenced from a resource-file and debug it with aapt?
aapt version is 0.2 from Android Tools Rev. 20.
Quoting Xav in his response to the dupe of this question asked on the adt-dev Google Group:
you cannot reference a resource in the minsdkVersion of your manifest.
While a lot of things in the manifest can reference resources, apparently minSdkVersion cannot.
Xav suggests using a script to change the manifest. Another approach would be to package the bulk of your app as an Android library project and creating two apps that use the library, one with each of your two minSdkVersion values.
Since I am already using Maven to build the project I solved the problem this way:
I moved the AndroidManifest.xml to a folder called: ${project.basedir}/filtered and replaced the minSdkVersion value in the AndroidManifest.xml with a property reference (I already had this in the pom.xml): ${project.property.minSdkVersion}:
<uses-sdk android:minSdkVersion="${project.property.minSdkVersion}" android:targetSdkVersion="15"/>
and removed it from the filtered/config.xml. Then I added the following resource-filtering directive to the pom.xml:
<project ...>
...
<properties>
<project.property.minSdkVersion>8</project.property.minSdkVersion>
</properties>
...
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>${project.basedir}/filtered</directory>
<targetPath>${project.basedir}/</targetPath>
<includes>
<include>AndroidManifest.xml</include>
</includes>
</resource>
</resources>
...
</build>
...
</project>
This way the filtered AndroidManifest.xml is at the place where Eclipse expects it and has the property reference replaced after calling mvn process-resources. In the other profiles I have different values for ${project.property.minSdkVersion}

Categories

Resources