Android portrait screen orientation doesn't work [React Native] - android

Hi I'm working on a react-native app and when I try to set the Android screen orietnation exclusively to portrait, it doesn't work, here's project specs:
RNNKotlinVersion = "1.6.0"
buildToolsVersion = "33.0.0"
minSdkVersion = 21
compileSdkVersion = 33
targetSdkVersion = 33
And here's my code in AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<application
tools:ignore="LockedOrientationActivity"
<activity
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"
What's wrong with this code?
thank you

Try to use this package https://github.com/wonday/react-native-orientation-locker
It works perfectly and allows you to control orientation from JS side.
import Orientation from 'react-native-orientation-locker';
...
Orientation.lockToPortrait();
...

Related

Black space at the bottom with targetSdkVersion 22 on a device with Android 11

Following bug occurs on a fairly new Motorola Defy with Android 11:
I have a weird black bottom bar in my app when my targetSdkVersion is 22 which disappears if I set 24 as targetSdkVersion.
The bug does not appear on my Motorola E2 with Android 5.
I'd wish to stay at targetSdkVersion 22 for valid reasons. The app will run on a very low number of known devices at our customer. The phone is locked up in some sort of a kiosk mode. targetSdkVersion 22 doesn't enforce RuntimePermissions which makes is perfect for the use as kiosk app.
Here's the stripped down build.gradle (:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
defaultConfig {
//...
minSdkVersion 17
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 22
versionCode 140
versionName "1.4.0 in dev " + new Date().format('yyyy-MM-dd HH:mm:ss')
}
}
dependencies {
//We don't plan to switch to AndroidX with our legacy Android apps that were written around API level 19
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
}
Here's the stripped down AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xxxxxxxxxxx">
<application
android:name="xxxxx.xxxxApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name="xxxxxx.PresetActivity"
android:configChanges="keyboardHidden|orientation"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateUnchanged"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here's the stripped down styles.xml (I only have one styles.xml):
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
</resources>
Stripped down activity code:
package xxxxxxxxxxx.ui.activity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import xxxxxxxxx.ui.fragment.PresetFragment;
import android.support.v7.app.AppCompatActivity;
public class PresetActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_container);
// Add fragment the correct way
// http://stackoverflow.com/questions/8474104/android-fragment-lifecycle-over-orientation-changes
Fragment fragment = getSupportFragmentManager().findFragmentById(
R.id.FragmentContainer);
if (fragment == null) {
FragmentTransaction fragmentTransaction = getSupportFragmentManager()
.beginTransaction();
fragmentTransaction.add(R.id.FragmentContainer,
new PresetFragment());
fragmentTransaction.commit();
}
}
}
activity_container.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="#color/color_background"
android:paddingTop="8dp"
tools:ignore="MergeRootFrame">
<fragment
android:id="#+id/status_bar_fragment"
class="xxx.ui.fragment.StatusBarFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="#layout/fragment_status_bar" />
<FrameLayout
android:id="#+id/FragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/status_bar_fragment"
android:layout_alignRight="#+id/status_bar_fragment"></FrameLayout>
</RelativeLayout>
The system assumes that your application cannot handle non standard aspect ratio and uses a 16:9 letterbox.
This can be controlled with resizeableActivity :
<activity
....
android:resizeableActivity="true"
If you don't set it, the default value is true if you target API 24 or greater, and false otherwise.

Manifest merger failed error (tools:replace="android:launchMode")

I updated the Android Studio to version 3.1 and the Gradle for my Project to version 3.1.0.
Since then I had some problems related to merging multiple files, but that I was able to solve.
Then I had this error:
> Manifest merger failed :
Attribute activity#com.aware.ui.PermissionsHandler#launchMode
value=(singleTop) from [com.awareframework:aware-core:4.0.555]
AndroidManifest.xml:35:13-43 is also present at
[com.github.denzilferreira:aware-client:4.0.555]
AndroidManifest.xml:44:13-42 value=(standard).
Suggestion: add 'tools:replace="android:launchMode"' to <activity>
element at AndroidManifest.xml:30:9-37:66 to override.
So, first I tried to use tools:replace="android:launchMode" inside the mentioned Activity:
<activity android:name=".MainActivity"
...
tools:replace="android:launchMode"
android:launchMode="standard">
</activity>
But it did not solve the problem, then I searched and found some similar questions and their responses.
One of them said to delete the proposed attribute from the libraries that were conflicting:
<activity
android:name="com.aware.ui.PermissionsHandler"
android:configChanges="keyboardHidden|orientation|screenSize"
android:excludeFromRecents="true"
android:exported="true"
android:launchMode="singleTop" //deleted this line from Manifests
android:noHistory="true"
android:theme="#style/Theme.AppCompat.Translucent" />
But again, with no success. I also tried to use tools:replace="android:launchMode" inside the application tag:
<application
...
tools:replace="android:launchMode">
An then use the android:launchMode="standard" inside the activity tag.
<activity android:name=".MainActivity"
....
android:launchMode="standard">
</activity>
But it throws a different error:
tools:replace specified at line:16 for attribute android:launchMode,
but no new value specified
I also tried to reorder the dependencies inside the Gradle files, like #GLee answered here but it did not make any difference.
This is one of the libraries I'm using that is conflicting: Aware Activity Recognition Plugin.
And this is the tutorial I used to create the application: Creating a standalone application.
Another relevant thing to say is that the two dependencies conflicting are in different modules, the com.awareframework:aware-core:4.0.555 dependency is inside the app module and the com.github.denzilferreira:aware-client:4.0.555 is inside the activity_recognition module.
Finally, this is my App Gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "app.miti.com.iot_reduce_daily_stress_application"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
...
}
dependencies {
...
implementation "com.awareframework:aware-core:${aware_libs}"
implementation "com.android.support:appcompat-v7:${support_libs}"
implementation "com.android.support:cardview-v7:${support_libs}"
implementation "com.google.android.gms:play-services-location:${gms_libs}"
implementation "com.google.android.gms:play-services-maps:${gms_libs}"
implementation "com.google.android.gms:play-services-places:${gms_libs}"
implementation 'com.android.support:preference-v14:${support_libs}'
implementation "com.android.support:design:${support_libs}"
implementation 'pub.devrel:easypermissions:1.2.0'
implementation 'com.android.support:multidex:1.0.3'
implementation "com.google.firebase:firebase-core:${firebase_libs}"
implementation "com.google.firebase:firebase-messaging:${firebase_libs}"
...
}
And this is my activity_recognition module Gradle file:
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 19
targetSdkVersion 27
versionCode version_code
versionName version_readable
multiDexEnabled true
}
...
}
dependencies {
...
implementation "com.google.android.gms:play-services-location:${google_libs}"
implementation "com.android.support:appcompat-v7:${support_libs}"
api "com.github.denzilferreira:aware-client:${aware_libs}"
implementation "com.koushikdutta.ion:ion:2.1.6"
implementation "org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2"
}
This is the App AndroidManifest.xml (error URL directs to this file):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="app.miti.com.iot_reduce_daily_stress_application">
... //permissions
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name="android.support.multidex.MultiDexApplication">
<activity android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SettingsActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:parentActivityName=".MainActivity"
tools:ignore="UnusedAttribute">
</activity>
</application>
</manifest>
Since this is not a dependencies version problem, like many other questions I found, and because I have to use this library dependencies in my Project, how can I solve this problem?
P.S: I have already tried the usual methods:
Invalidate Caches/Restart
Deleted Gradle
Clean Project and Rebuild Project
...
The problem is with com.aware.ui.PermissionsHandler, which is why putting attributes on .MainActivity will not help, as that is a different activity. Since you are using artifacts in your posted Gradle files, I'm not sure where you were modifying the manifests of the libraries.
In your app's manifest, add:
<activity
android:name="com.aware.ui.PermissionsHandler"
android:launchMode="..."
tools:replace="android:launchMode"
/>
where ... is your desired launchMode value, perhaps after some discussion with the developers of those libraries to determine what the right answer is.
You shouldn't need any other attributes or child elements — they should all get merged in via the manifest merger process.

how to change android packagename only?

I have a small android application with this manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.eliran.myapplication" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.eliran.myapplication.MainActivity"
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>
</manifest>
I want alter the package name for testing integration with another andorid app.
However when I change to
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myTest.driver" >
I get an error that R class is not found
Error:(37, 25) error: package R does not exist
how can i fix this, with minimal effort and without changing the package name of each class?
Step #1: Return your package attribute to its original value
Step #2: Add applicationId to defaultConfig in your module's build.gradle file to your revised application ID
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
applicationId "com.commonsware.android.espresso"
}
}
This gives your app a separate application ID (the unique identifier for installation purposes) but keeps the package name the same (for R generation, etc.).
You need to change the applicationID in your build.gradle file

App works in emulator but not on phone

The app I am developing works perfectly on my emulator, but it won't work on my phone when I try to debug it. I only get the message:
Warning: debug info can be unavailable. Please close other application using ADB: Monitor, DDMS, Eclipse
Restart ADB integration and try again.
Waiting for process: com.deliciouslymad.tsukasa.critterbytes
It hangs there forever with no change on my phone. It doesn't work after restarting or cleaning the project, either. I've tried many solutions on this site already, but none of them have resolved this issue.
-UPDATE-
ADB logs:
ddms: null
java.lang.NullPointerException
at com.android.ddmlib.Client.sendAndConsume(Client.java:673)
at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:195)
at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:66)
at com.android.ddmlib.Client.getJdwpPacket(Client.java:772)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)
The .apk installs on my phone just fine.
I have 'USB debugging', 'allow mock locations', and 'verify apps over USB' turned on in my phone settings. Runtime is Dalvik and it's connected as a media device.
My phone runs Android 4.4.4.
If it helps, I am implementing the Zxing library into my code for barcode scanning.
Here's my AndroidManifest.xml code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.deliciouslymad.tsukasa.critterbytes">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity android:name="ScannerActivity"
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>
</manifest>
Here's my build.gradle code:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.deliciouslymad.tsukasa.critterbytes"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.1.0'
}
Additionally, in my app's project structure, the 'Compile Sdk Version' is API 21 and the 'Build Tools Version' is 21.1.2. 'Source Compatibility' and 'Target Compatibility' are blank, and I'm not sure if anything is supposed to be there.
The gradle builds fine with no errors, but there is something strange; when I hover over 'getDefaultProguardFile' in the build.gradle file, it says that it cannot resolve the symbol.
I am a junior programmer and trying to learn, so please let me know if there's anything missing or anything I can improve! This is all a little overwhelming and I can't figure out why it's not working.

android.compileSdkVersion is missing

Im using AndroidStudio and Im trying to put some ads on my app, according to the setting up google play API - https://developer.android.com/google/play-services/setup.html
Adter i sync the project with the grandle files i get this error:
Error:Failed to find: com.google.android.gms:play-services:5.0.77
Install Repository and sync project<br>Open File<br>Open in Project Structure dialog
This is my gradle.build:
apply plugin: 'com.android.application'
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.pachu.fartsounds"
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.google.android.gms:play-services:5.0.77'
}
My Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pachu.fartsounds">
<application
android:allowBackup="true"
android:icon="#drawable/fart_icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".FartActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Any ideas? Thanks !
You are missing critical components of your manifest. The SDK error you are receiving is because the compiler doesn't know at what SDK level to compile your app - you're missing <uses-sdk.
And while we're at it, you're also missing your package name, version name, and version code. These are all critical components to your app. Here's an example of a well-formed manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.exampleapp"
android:versionCode="2"
android:versionName="v0.2-Alpha" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.GET_TASKS" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.exampleapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:enabled="true" android:name="com.example.exampleapp.MyService" />
</application>
</manifest>
Notice at the very top: the sections that read package, android:versionCode, and android:versionName. And also, below those, the entire section that starts with <uses-sdk... These are all required.
Add this to your build.gradle:
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
}
I had the same issue and fixed it next way:
in build.gradle file of module (usually in app, not in root project directory) I set
android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 19
// your application version and id settings
}
where 19 - is and SDK I have completely loaded in Android SDK Manager
(same values checked in Studio module settings, Properties and Flavors tabs).
So, may be your problem is a cause of minSdkVersion 8 value, when you don't have 8 API installed.
I had the same error.
In my case the package 'Extras\Google Repository' was not installed.
So after installing it in SDK Manager the problem had gone.

Categories

Resources