Android emulator for nativescript don't work - linux

I don't know why my Nativescript App don't launch on my android emulator..
More explanation :
I'm on Manjaro (Linux).
I have install android studio and setup environment variable like :
JAVA_HOME=/usr/lib/jvm/default
ANDROID_SDK_ROOT=$HOME/Android/Sdk
ANDROID_HOME=$HOME/Android/Sdk
ANDROID_AVD_HOME=$HOME/.android/avd
NPM=$HOME/.npm-global/bin
COMPOSER=$HOME/.config/composer/vendor/bin
export PATH=$PATH:$NPM:$COMPOSER::$ANDROID_SDK_ROOT:$ANDROID_HOME:$ANDROID_AVD_HOME:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$JAVA_HOME
After launch my device in emulator of android studio when I make "tns run android --emulator"
this append :
✖ The ANDROID_HOME environment variable is not set or it points to a non-existent directory. You will not be able to perform any build-related operations for Android.
To be able to perform Android build-related operations, set the `ANDROID_HOME` variable to point to the root of your Android SDK installation directory.
✖ WARNING: adb from the Android SDK is not installed or is not configured properly.
For Android-related operations, the NativeScript CLI will use a built-in version of adb.
To avoid possible issues with the native Android emulator, Genymotion or connected
Android devices, verify that you have installed the latest Android SDK and
its dependencies as described in http://developer.android.com/sdk/index.html#Requirements
✖ Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK 28.
Run `$ sdkmanager` to manage your Android SDK versions.
✖ You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=23 <=28'.
Run `$ sdkmanager` from your command-line to install required `Android Build Tools`. In case you already have them installed, make sure `ANDROID_HOME` environment variable is set correctly.
✖ Error executing command 'javac'. Make sure you have installed The Java Development Kit (JDK) and set JAVA_HOME environment variable.
You will not be able to build your projects for Android.
To be able to build for Android, verify that you have installed The Java Development Kit (JDK) and configured it according to system requirements as
described in http://docs.nativescript.org/setup/ns-cli-setup/ns-setup-linux.html#system-requirements
✖ WARNING: The Java Development Kit (JDK) is not installed or is not configured properly.
I don't know why..

Related

After creating a NativeScript Typescript application, I tried running it using the command "ns run android" it doesnt run and i get the output

After creating a NativeScript Typescript application, I tried running it using the command ns run android I get this output and does not run.
The ANDROID_HOME environment variable is not set or it points to a non-existent directory. You will not be able to perform any build-related operations for Android.
To be able to perform Android build-related operations, set the ANDROID_HOME variable to point to the root of your Android SDK installation directory.
WARNING: adb from the Android SDK is not installed or is not configured properly.
For Android-related operations, the NativeScript CLI will use a built-in version of adb.
To avoid possible issues with the native Android emulator, Genymotion or connected
Android devices, verify that you have installed the latest Android SDK and
its dependencies as described in http://developer.android.com/sdk/index.html#Requirements
WARNING: The Android SDK is not installed or is not configured properly.
You will not be able to run your apps in the native emulator. To be able to run apps
in the native Android emulator, verify that you have installed the latest Android SDK
and its dependencies as described in http://developer.android.com/sdk/index.html#Requirements
Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK 28 or later.
Run $ sdkmanager to manage your Android SDK versions.
No compatible version of the Android SDK Build-tools are installed on your system. You can install any version in the following range: '>=23 <=32'.
Install the required build-tools through Android Studio. In case you already have them installed, make sure the ANDROID_HOME environment variable is set correctly.
Your errors and warnings says that you haven't Android SDK and adb which one is included in the Android SDK Platform-Tools package.
First of all, you need to read this doc and complete steps in it - https://docs.nativescript.org/environment-setup.html. This documentation has everything you need, based on your operating system and the operating system you want to develop the application for.
If you already install everything docs says, check your path environment for ANDROID_HOME and adb variables presence, if not, add them. For example, my path (on MacOS) contains following lines:
/Users/sixhellstations/Library/Android/sdk/emulator:/Users/sixhellstations/Library/Android/sdk/tools:/Users/sixhellstations/Library/Android/sdk/tools/bin:/Users/sixhellstations/Library/Android/sdk/platform-tools

Getting "ANDROID_HOME environment variable is not set" when running "ns run" & "ns doctor android"

I'm using MacOS. I've already used Android Studio and Xcode to one of my react-native projects before. I am now learning SvelteNative. As I've started following the docs here and here, and got onto the step where I need to run ns doctor android I get this error:
zeddrix#Zeddrixs-MacBook-Pro todoapp % ns doctor android
✔ Getting environment information
TIP: To avoid setting up the necessary environment variables, you can use the Homebrew package manager to install the Android SDK and its dependencies.
There seem to be issues with your configuration.
✔ Getting NativeScript components versions information...
✔ Component nativescript has 8.1.2 version and is up to date.
⚠ Update available for component #nativescript/core. Your current version is 7.0.0 and the latest available version is 8.1.3.
⚠ Update available for component #nativescript/android. Your current version is 7.0.0 and the latest available version is 8.1.1.
✔ Javac is installed and is configured properly.
✔ The Java Development Kit (JDK) is installed and is configured properly.
✔ Xcode is installed and is configured properly.
✔ xcodeproj is installed and is configured properly.
✔ CocoaPods are installed.
✔ CocoaPods update is not required.
✔ CocoaPods are configured properly.
✔ Your current CocoaPods version is newer than 1.0.0.
✔ Python installed and configured correctly.
✔ The Python 'six' package is found.
✔ Xcode version 13.0.0 satisfies minimum required version 10.
✖ The ANDROID_HOME environment variable is not set or it points to a non-existent directory. You will not be able to perform any build-related operations for Android.
To be able to perform Android build-related operations, set the `ANDROID_HOME` variable to point to the root of your Android SDK installation directory.
✖ WARNING: adb from the Android SDK is not installed or is not configured properly.
For Android-related operations, the NativeScript CLI will use a built-in version of adb.
To avoid possible issues with the native Android emulator, Genymotion or connected
Android devices, verify that you have installed the latest Android SDK and
its dependencies as described in http://developer.android.com/sdk/index.html#Requirements
✖ WARNING: The Android SDK is not installed or is not configured properly.
You will not be able to run your apps in the native emulator. To be able to run apps
in the native Android emulator, verify that you have installed the latest Android SDK
and its dependencies as described in http://developer.android.com/sdk/index.html#Requirements
✖ Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK 28 or later.
Run `$ sdkmanager` to manage your Android SDK versions.
✖ You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=23 <=30'.
Run `$ sdkmanager` from your command-line to install required `Android Build Tools`. In case you already have them installed, make sure `ANDROID_HOME` environment variable is set correctly.
Cannot read property 'toLowerCase' of null
zeddrix#Zeddrixs-MacBook-Pro todoapp %
I get this too when running ns run:
zeddrix#Zeddrixs-MacBook-Pro todoapp % ns run
✔ Javac is installed and is configured properly.
✔ The Java Development Kit (JDK) is installed and is configured properly.
✖ The ANDROID_HOME environment variable is not set or it points to a non-existent directory. You will not be able to perform any build-related operations for Android.
To be able to perform Android build-related operations, set the `ANDROID_HOME` variable to point to the root of your Android SDK installation directory.
✖ WARNING: adb from the Android SDK is not installed or is not configured properly.
For Android-related operations, the NativeScript CLI will use a built-in version of adb.
To avoid possible issues with the native Android emulator, Genymotion or connected
Android devices, verify that you have installed the latest Android SDK and
its dependencies as described in http://developer.android.com/sdk/index.html#Requirements
✖ WARNING: The Android SDK is not installed or is not configured properly.
You will not be able to run your apps in the native emulator. To be able to run apps
in the native Android emulator, verify that you have installed the latest Android SDK
and its dependencies as described in http://developer.android.com/sdk/index.html#Requirements
✖ Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK 28 or later.
Run `$ sdkmanager` to manage your Android SDK versions.
✖ You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=23 <=30'.
Run `$ sdkmanager` from your command-line to install required `Android Build Tools`. In case you already have them installed, make sure `ANDROID_HOME` environment variable is set correctly.
Your environment is not configured properly and you will not be able to execute local builds.
Verify that your environment is configured according to the system requirements described at
https://docs.nativescript.org/environment-setup.html#macos-android.
zeddrix#Zeddrixs-MacBook-Pro todoapp %
I tried uninstalling Android studio and then installing it again because I was thinking it could be the cause but still nothing. I didn't do this with Xcode because it takes very long to get it downloaded and since this error about ANDROID doesn't seem to have a connection about Xcode.
Then I searched for solving the issue about the missing or misplaced ANDROID_HOME environment variable. This article helped me.
So I ran:
cd ~/
touch .bash_profile
open -e .bash_profile
And then put these in .bash_profile:
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools
But still got nothing... I don't know how to solve the next warnings below this, too. Help.
After days of waiting and researching, I've read the official Android Studio docs for setting env vars. And saw that:
(ANDROID_SDK_ROOT) Sets the path to the SDK installation directory. Once set, the value
does not typically change, and can be shared by multiple users on the
same machine. ANDROID_HOME, which also points to the SDK installation
directory, is deprecated. If you continue to use it, the following
rules apply: If ANDROID_HOME is defined and contains a valid SDK
installation, its value is used instead of the value in
ANDROID_SDK_ROOT. If ANDROID_HOME is not defined, the value in
ANDROID_SDK_ROOT is used. If ANDROID_HOME is defined but does not
exist or does not contain a valid SDK installation, the value in
ANDROID_SDK_ROOT is used instead.
I know that I can do this for ANDROID_HOME. But since the docs says here that it's deprecated, I've decided to do this on the ANDROID_SDK_ROOT instead. I opened up my Terminal and ran this:
set ANDROID_SDK_ROOT=Users\zeddrix\Library\Android\sdk\
It seemed like the CLI is waiting for another command after I did this so I then did this:
export ANDROID_SDK_ROOT=/Users/zeddrix/Library/Android/sdk
If that doesn't work, try this:
set ANDROID_HOME=Users\zeddrix\Library\Android\sdk\
Then:
export ANDROID_HOME=/Users/zeddrix/Library/Android/sdk
The error about this ANDROID_HOME has gone. Now I only had one error left to solve:
You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=23 <=30'.
Run `$ sdkmanager` from your command-line to install required `Android Build Tools`. In case you already have them installed, make sure `ANDROID_HOME` environment variable is set correctly.
The first comment in this question helped me through. I went to SDK Manager of my Android Studio > SDK Tools and then as #Kevin McCarpenter said:
"Uncheck (check actually) 'Show Package Details' and then you can select
a lower version. If you're not building for android 12 (and you
probably aren't yet), you can uncheck '31.0.0' and check '30.0.3'.
After that, go into the build.gradle in your app and change
buildToolsVersion '31.0.0' to buildToolsVersion '30.0.3'"
Then I ran ns run android (as said when I run ns run --help) and it finally worked!

Android studio is giving the following error when I am trying to build a ionic project "Gradle sync failed: Sync failed: reason unknown"

I am trying to build a ionic project in Android studio on Ubuntu 20.04 . I am using the command ionic capacitor build then android studio opens up as expected then it shows this error Gradle sync failed: Sync failed: reason unknown. I am unable find a solution for this particular gradle sync error. I have reinstalled Ubuntu and other things but still the problem persists.
In my case, a fresh install of Android Studio resulted in Android 31 being the only SDK available but the project was targeting Android 30. I went to Tools > SDK Manager and made sure the appropriate version of Android SDK was installed and available. After restarting, and allowing the gradle sync to complete I was able to build/run the app on a virtual device, etc.
Here is what I found
This is the screenshot thanks for helping.
Capacitor lets you manage your own Android project. Like any IDE-backed project, sometimes things get so out of sync that the only solution is to rebuild the project.
To do this, follow these steps:
Copy any source code you created (such as Java files in app/android/src, manifest files, or resource files) into a safe location outside of app/android.
Next, make sure you are running an updated version of the Capacitor CLI:
npm install #capacitor/cli#latest
Remove the android directory:
rm -rf android/
Re-create the Android app from Capacitor:
npx cap add android
Copy your saved source files back into the project.
Check the error log. You should find something like "Module: 'mobile' platform 'android-30' not found" or something similar. Click Tools > SDK Manager and download the appropriate Android SDK Platform package.
on top right you will see option to view log file upon clicking there you will redirect to file manager and open idea file there
example :
open idea file and scroll down you will see actual issue.
In my case android sdk 31 was not installed.
I installed android sdk 31 from File>Settings>Apprearance and behaviour>system settings>android sdk and install required android sdk and rebuild the project.
accord to my observation in most cases you get this error because you have not required sdk installed in your system.

Flutter Secure Storage not working after build in release mode

Everything works fine in debug mode and release on emulator, but reading values from FlutterSecureStorage fails on a physical device. Other functionalities in application work properly, when I comment using FlutterSecureStorage.
After installing .apk file and launching application on a device, it uses FlutterSecureStorage to get information if user is logged in or not, along with other values. I expect null during first run, of course, but storage.read(key) seams to fail before returning any value.
Added backup tags in main/AndroidManifest.xml
<application
...
android:allowBackup="false"
android:fullBackupContent="false">
Added deleting keys on startup
final FlutterSecureStorage storage = FlutterSecureStorage();
Future<void> checkIfUserIsSignedIn() async {
storage.deleteAll();
try{
isUserSignedIn = await storage.read(key: _isLoggedIn);
}
catch (e){
print(e);
}
setState(() {});
}
Tried with FlutterSecureStorage v.3.3.3 and FlutterSecureStorage v.3.2.0, but there was no change.
I checked SDK version of my device (Honor 10) - 29. Also checked on other device (Samsung Galaxy S9+), but the issue also occurs.
Running flutter run --release causes warnings:
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: C:\Users\karo\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_secure_storage-3.2.0\android\src\main\java\com\it_nomads\fluttersecurestorage\FlutterSecureStoragePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
and error:
Installing build\app\outputs\flutter-apk\app.apk... 376ms
Error: ADB exited with exit code 1
Performing Streamed Install
adb: failed to install C:\Users\karo\idom_mobile\build\app\outputs\flutter-apk\app.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.project.idom signatures do not match previously installed version; ignoring!]
Uninstalling old version...
Installing build\app\outputs\flutter-apk\app.apk... 6.9s
but successfully installs application on emulator and everything works as expected.
The problem is when I install application on physical device. To generate .apk I use flutter build apk --release and install using app-release.apk file as stated in build log:
flutter build apk --release
You are building a fat APK that includes binaries for android-arm, android-arm64, android-x64.
If you are deploying the app to the Play Store, it's recommended to use app bundles or split the APK to reduce the APK size.
To generate an app bundle, run:
flutter build appbundle --target-platform android-arm,android-arm64,android-x64
Learn more on: https://developer.android.com/guide/app-bundle
To split the APKs per ABI, run:
flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi
Learn more on: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 69.9s
√ Built build\app\outputs\flutter-apk\app-release.apk (48.9MB).
My flutter doctor -v
flutter doctor -v
[√] Flutter (Channel dev, 1.24.0-10.2.pre, on Microsoft Windows [Version 10.0.18362.1198], locale en-GB)
• Flutter version 1.24.0-10.2.pre at C:\Users\karo\flutter
• Framework revision 022b333a08 (27 hours ago), 2020-11-18 11:35:09 -0800
• Engine revision 07c1eed46b
• Dart version 2.12.0 (build 2.12.0-29.10.beta)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at C:\Users\karo\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[√] Android Studio (version 4.1.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] Connected device (1 available)
• Android SDK built for x86 64 (mobile) • emulator-5554 • android-x64 • Android 10 (API 29) (emulator)
• No issues found!
I tried to make sure my project is migrated to AndroidX and got a message: No Usages Found in the Project.
I don't have any more ideas, could you help me?
EDIT
I tried using SharedPreferences as a temporary workaround, but it still didn't work - as I guess, the package was not initialized.
I built my app with flutter build apk --release --no-shrink after reading this thread https://github.com/flutter/flutter/issues/65334.
Then tried flutter build apk --release --no-shrink with the version of my application that uses FlutterSecureStorage and it worked.
Should I really consider it as a valid fix and always build my application this way?
How are you initializing the package? The issue seems to occur while the app runs in the background, A workaround posted in this thread is by registering the plugins on Android's MainActivity - this adds FlutterSecureStoragePlugin.
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine)
}
}
You can fix this like I did
Check in pubspec.yml
environment:
sdk: ">=2.16.2 <3.0.0"
and
flutter_secure_storage: ^4.2.1
Check in android/app/build.gradle
compileSdkVersion 32
did you add the permission to your manifest file?
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

Unable to locate android sdk Flutter Mac

I am a new user to flutter and i installed android studio and flutter plug in. While running my flutter doctor -v it shows. I don't know how to fix it. help me out. I tried a lot to fix it but nothing helps me
[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from:
https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK
components.
(or visit https://flutter.dev/docs/get-started/install/macos#android-setup
for detailed instructions).
If the Android SDK has been installed to a custom location, set
ANDROID_SDK_ROOT to that location.
You may also want to add it to your PATH environment variable.
[✗] Xcode - develop for iOS and macOS
✗ Xcode installation is incomplete; a full installation is necessary for iOS
development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin
code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To install:
sudo gem install cocoapods
[✓] Android Studio (version 3.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 34.0.1
• Dart plugin version 182.5215
• Java version OpenJDK Runtime Environment (build
1.8.0_152-release-1248-b01)
[!] Android Studio
• Android Studio at /Users/apple/Developer/flutter/Contents
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
✗ Android Studio not found at /Users/apple/Developer/flutter/Contents
• Try updating or re-installing Android Studio.
[!] Connected device
! No devices available
Please go to Project Structure and solve some errors.
Android Studio -> File -> Project Structure.
Please check that you install dart and flutter plugin in the android studio.
Please install Dart in your system also.
is there local.properties file present in your project, inside android folder ?
if not , then create a local.properties file and put your android sdk path inside it, like in my case
sdk.dir=/Users/tusharpandey/Library/Android/sdk

Resources