problem with RTL layout in react native project only when i release apk - react-native

i am building an app that need to support only rtl layout no matter what is the phone language.
my problem is when i am in debug mode its work just fine and show the layout rtl as i wanted regardless the phone language but after i release the app it show the the layout direction as the phone language.
can anyone tell me what it may be ?
i tried the following solution:
add this line in the constructor of the main page
I18nManager.allowRTL(true);
I18nManager.forceRTL(true);
also add this line in android manifest:
android:supportsRtl="true"
both in activity tag and also in application tag
manifest :
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true"
android:supportsRtl="true"
>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:supportsRtl="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
constructor in App.js
constructor(){
super();
I18nManager.allowRTL(true);
I18nManager.forceRTL(true);
}
this is the good result
https://i.imgur.com/S2nV0a4.jpg
this one is not what i want
https://i.imgur.com/VXzYWI1.png

Add these three lines in your MainActivity.java
+ import com.facebook.react.modules.i18nmanager.I18nUtil;
#Override
public void onCreate() {
super.onCreate();
// FORCE RTL
+ I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
+ sharedI18nUtilInstance.allowRTL(getApplicationContext(), true);
....
}

Related

While releasing react native app to the play store getting error, This file can't be installed on Android 12 or higher

You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver with intent filter, but without the 'android:exported' property set. This file can't be installed on Android 12 or higher. See: developer.android.com/about/versions/12/behavior-changes-12#
I have added the property 'android:exported' to the AndroidManifest.xml. But the same issue occurs while uploading
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.domain.example">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application android:name=".MainApplication" android:label="#string/app_name" android:usesCleartextTraffic="true" android:icon="#mipmap/ic_launcher" android:allowBackup="false" android:theme="#style/AppTheme"
android:exported="true">
<activity android:name=".MainActivity" android:label="#string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- You will also only need to add this uses-library tag -->
<uses-library android:name="org.apache.http.legacy" android:required="false" />
</application>
</manifest>

React native admob installing

Hi I'm trying to show ads in my sample app.I got verified admob and firebase account. My steps:
Installing admob
npm i -S react-native-admob#next
Linking
react-native link react-native-admob
android/app/src/main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
//it should be here ***
//I added this line
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-6758XXXX6788401~XXXXXXXXX"/>
</application>
//I added this line
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-6758XXXX6788401~XXXXXXXXX"/>
</manifest>
App.js
import {AdMobBanner} from 'react-native-admob';
const Example = () => {
return (
<ImageBackground source={require('./assets/bg.jpg')} style={styles.ImageBg}>
<StatusBar hidden={true} />
<SafeAreaView style={{ flex: 1, alignItems: 'center', }}>
<AdMobBanner
adSize="largeBanner"
adUnitID="ca-app-pub-67584xxx6788401/19xxx7"
testDeviceID="CF583E54-34C6-453C-80FC-493D2468A51E" //I don't know this
didFailToReceiveAdWithError={onFailToRecieveAd}
/>
....
it gived error in node_modules/react-native-admob in three java files.
Error: "react-native-admob:compileReleaseJavaWithJavac FAILED " I solved it with
import android.support.annotation.Nullable
to
import androidx.annotation.Nullable;
now it's not giving error but not working too.It gives Unfortunately app has stopped
SOLUTION.
I fixed now it's because of the metadata. Now it shows test ads. How can I show real ads in react native.
Thank you

React Native Android launchMode singleTask getLaunchOptions doesn't get called again

I am developing a react-native app for Android. The app takes image sharing with this intent-filter on the main activity
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
I am able to get the initial sharing intent images by overriding getLaunchOptions(), but with this default launchMode="singleTask", I am not able to get new sharing intent when I have the existing instance of the app running.
So, how can I get the new sharing intent while have an instance of the app running?
PS: changing the launchMode to standard to standard kind of solved my problem, but that will create multiple instances of the app.
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I have the same problem. If the launchMode isn't in AndroidManifest.xml the situation is like standart.
I've found a solution for my case (receiving intents for .txt files)
In AndroidManifest.xml
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
...
<intent-filter tools:ignore="AppLinkUrlError">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
In MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
onNewIntent(this.getIntent());
}
#Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// here are received intents
}
In such way I receive intents when app in background or it is not run at all and only ONE instance of the app.
I'm using React Native 0.61 and was having the exact same problem.
I've used the react-native-share-menu lib to make it work.
Alternatively, If you don't want to add a new lib to your project, it might be worth taking a look at how they did it for Android and modify your code accordingly:
https://github.com/meedan/react-native-share-menu/tree/master/android/src/main

Android: react-native-image-picker manifest.xml invalid file path

Sorry if i don't fully respect the question pattern, it is my first question on StackOverflow. :)
I am trying to run my react native app on Android (for the first time) after a long period of code (I was only testing on iOS).
I have been fixing a lot of issues mentioned by Android Studio but can't figure out the following one:
error: invalid file path 'my_path/node_modules/react-native-image-picker/android/build/intermediates/manifests/aapt/release/AndroidManifest.xml'.
My config:
"react-native-image-picker": "^0.27.2"
"react-native": "0.56.0"
I have followed the path mentioned above, and the file exist and doesn't seem to have any error in it.
I also followed the install doc from react-native-image-picker
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:allowBackup="false"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
Please do below steps to resolve.
File > Invalidate Caches/Restart

Splash screen on Android

I have a problem with the splashscreen on Android. Here is everything what I am doing:
Creating background_splash.xml file:
xml version="1.0" encoding="utf-8"?>
layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#android:color/darker_gray"/>
<item>
<bitmap
android:gravity="center"
android:src="#drawable/splash"/>
</item>
I remove < in the first two lines because stackoverflow cannot display them. This file is located in drawable.
I added the following to styles.xml:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
and this is my manifest files:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22" />
<application
android:name=".MainApplication"
android:allowBackup="true"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:theme="#style/AppTheme">
<activity
android:name=".SplashActivity"
android:label="#string/app_name"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
And also the activity:
import android.content.Intent;
import android.os.Bundle;
import com.facebook.react.ReactActivity;
public class SplashActivity extends ReactActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
This is the error I have:
Starting the app on 51d123cc (adb -s 51d123cc shell am start -n com.test/.MainActivity)...
Starting: Intent { cmp=com.test/.MainActivity }
java.lang.SecurityException: Permission Denial: starting Intent { flg=0x10000000 cmp=com.test/.MainActivity } from null (pid=20601, uid=2000) not exported from uid 11152
at android.os.Parcel.readException(Parcel.java:1540)
at android.os.Parcel.readException(Parcel.java:1493)
at android.app.ActivityManagerProxy.startActivityAsUser(ActivityManagerNative.java:2589)
at com.android.commands.am.Am.runStart(Am.java:768)
at com.android.commands.am.Am.onRun(Am.java:307)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
at com.android.commands.am.Am.main(Am.java:102)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:255)
UPDATE:
To the answer of #Ankit Prajapati I will add also that I set
android:largeHeap="true"
which was an error from Android Studio (running from the terminal this error wasn't reported) and this happen after changing activity to SplashActivity.
Also it was necessary to change edit configurations and changing "Launch Activity" to "Specified Activity" and setting com.test.SplashActivity.
Second way of managing splash screen on Android and which I use right now is with this tutorial:
Splash Screen Android
Try using this in
android:exported="true" in the manifest file in the activity you are trying to start (Loading Activity)
Like this
<activity
android:name=".SplashActivity"
android:label="#string/app_name"
android:theme="#style/SplashTheme"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Also Add
Intent intent = new Intent(SplashActivity.this, MainActivity.class);