01 August, 2020

React Native: Fix adb - device is offline error and Execution failed for task ':app:installDebug' and other

What went wrong: Android ADB device offline, can't issue commands


Easy to fix just follow the following steps:


Open CMD(command prompt) and below commands in order

  1. Kill the running ADB server using "adb kill-server"
  2. Start ADB server using "adb start-server"
  3. check running devices status using "adb devices"
  4. if your device is offline then run following this command "adb  reconnect device"


'ADB' is not recognized as an internal or external command, operable program or batch file


How to Fix It? 


Open cmd and run following command "PATH %PATH%;C:\Users\<user name here>\AppData\Local\Android\sdk\platform-tools"


Clean up you android build:

Try this one: 

cd android && ./gradlew clean 


What went wrong: Execution failed for task ':app:processDebugManifest'.

> Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 24 declared in library [:react-native-ffmpeg] D:\Surya\learn\AwesomeProject\node_modules\react-native-ffmpeg\android\build\intermediates\library_manifest\debug\AndroidManifest.xml as the library might be using APIs not available in 16

        Suggestion: use a compatible library with a minSdk of at most 16,

                or increase this project's minSdk version to at least 24,

How to Fix It? 


Open build.dradle and update minSdkVersion =24 according to above suggestions


minSdkVersion


 What went wrong: Execution failed for task ':app:installDebug'.

    > com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: Unknown failure: cmd: Can't find service: package


How to Fix It?

Just ran into the same error. In my case, the emulator was frozen. I had to go to AVD Manager in Android Studio and run "Cold Boot Now" on the specific emulator to get it back up, then this error went away.

Cold Boot Now




Error Message: ADB manager: unable to locate ADB

How to Fix It?


make sure the following options are selected and installed properly in Android SKD.
    SDK Tools Tabs: 
            make sure  the under Android SDK Build Tools >> 29.0.2 is checked

make sure  the under Android SDK Build Tools >> 29.0.2 is checked

SDK Platforms Tab>>Android 10.0(Q) is installed

SDK Platforms Tab>>Android 10.0(Q) is installed


Issue:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute data@scheme at AndroidManifest.xml requires a placeholder substitution but no value for <appAuthRedirectScheme> is provided


How to Fixe it?

some android build keeps cache based on the build just we need to fix it cleaning the android project with the following command

Window 10:  clean android project

run following commond: cd android && gradlew clean
Install React Native cli global: run the follwoing command
npm install -g react-native-cli

28 July, 2020

React Native Expo Save File to Device in Given Folder

React Native Expo: Save File to Device in Given Folder

Currently, there is no easy solution and feature or trick or tutorial how to write files on internal storage and that is very tedious work to save find on the given provided folder and  app directory with expo without detaching

I want to save files on internal storage like Downloads, WhatsApp, DCIM, Pictures

This feature useful for the app with download files/picture/music feature. 

In this working tutorial, we are going to download video files from the server and the same file will be moved to the desire device folder.

Here are steps that you need to do,  This is working code in ANDROID and that should work on iOs as well.

You need to install following expo packages expo-media-library, expo-permissions and expo-file-system

  • Permissions.CAMERA_ROLL Permission is required, that should be fine.
  • Using FileSystem to download video, it will provide local URI from device
  • After call saveFile method to move the file to the desired folder.


import * as MediaLibrary from 'expo-media-library';

import * as Permissions from 'expo-permissions';

 import * as FileSystem from 'expo-file-system';

const saveFile = async (fileUri=> {

  const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);

  if (status === 'granted') {

    const asset = await MediaLibrary.createAssetAsync(fileUri);

    await MediaLibrary.createAlbumAsync('<FOLDER NAME>'assetfalse);

  }

};

 const fileDownLoad = async () => {

    let lastIndex = media?.uri.lastIndexOf('/');

    let fileName = media?.uri.substring(lastIndex);

 

    let downloadResumable = FileSystem.createDownloadResumable(

      "http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4",

      FileSystem.documentDirectory + fileName,

      {},

      () => {

        // down progress monitor here

      }

    );

    try {

      const { uri } = await downloadResumable.downloadAsync().then((item=> {

        return item;

      });

 

      await saveFile(uri)

        .then((rs=> {

          alert('Video saved to download folder);

        });

    } catch (e) {

      console.error(e);

    }

  };