Unable to apply changes on device: emulator-5554. Error is: Command gradlew.bat failed with exit code 1

Viewed 1096

I begin new project with NativeScript, but after more and more try i couldn't fix my error.

After build my application with:

tns run android --device Pixel_4_API_30

i have this error :

Unable to apply changes on device: emulator-5554. Error is: Command gradlew.bat failed with exit code 1.**

...............................................................................................

My trace loge :

#############################################################################
   WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING

   Debug level logging will leak security sensitive information!

   https://docs.gradle.org/6.4/userguide/logging.html#sec:debug_security
#############################################################################

Command gradlew.bat failed with exit code 1
Will send the following information to Google Analytics: {
  type: 'googleAnalyticsData',
  category: 'CLI',
  googleAnalyticsDataType: 'event',
  action: 'Performance',
  label: 'AndroidProjectService__buildProject',
  customDimensions: { cd2: 'Angular', cd9: 'false', cd5: 'CLI' },
  value: 3529
}
Error: Command gradlew.bat failed with exit code 1
    at Errors.failWithOptions (C:\Users\BRYAN\AppData\Roaming\nvm\v12.13.0\node_modules\nativescript\lib\common\errors.js:157:27)
    at Errors.fail (C:\Users\BRYAN\AppData\Roaming\nvm\v12.13.0\node_modules\nativescript\lib\common\errors.js:130:21)
    at GradleCommandService.<anonymous> (C:\Users\BRYAN\AppData\Roaming\nvm\v12.13.0\node_modules\nativescript\lib\services\android\gradle-command-service.js:40:30)
    at Generator.throw (<anonymous>)
    at rejected (C:\Users\BRYAN\AppData\Roaming\nvm\v12.13.0\node_modules\nativescript\lib\services\android\gradle-command-service.js:6:65)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

tns info :

√ Getting NativeScript components versions information...
√ Component nativescript has 7.2.0 version and is up to date.
‼ Update available for component @nativescript/core. Your current version is 7.1.4 and the latest available version is 7.3.0.
√ Component @nativescript/ios has 7.2.0 version and is up to date.
√ Component @nativescript/android has 7.0.1 version and is up to date.
2 Answers

I had exactly the same problem (Windows 10, August 2022). I had not used Android Studio for about two years. I had to upgrade Android Studio and Java 8 to Java 11 and some other stuff and then arrived at the same error message.

I went to Android Studio. I selected from the main menu -> Tools -> Device Manager. I saw the following message, so I clicked check for updates.

enter image description here

And then in the bottom right of the screen, I saw the following message and so I clicked update:

enter image description here

I noticed that I had two old emulators created in Android Studio, Pixel 2 API 24 and Pixel 2 API 27, so I clicked Create device and created Pixel XL API 31.

I was getting the following message now too.

Execution failed for task ':app:checkDebugAarMetadata'.
One or more issues found when checking AAR metadata values:

Dependency 'androidx.fragment:fragment:1.4.1' requires 'compileSdkVersion' to be set to 31 or higher.
Compilation target for module ':app' is 'android-28'

I had a look at NativeScript's article about Gradle Hooks here. I found the app.gradle file in my NativeScript project in the App_Resources/Android folder and updated the following:

android {
   ...
   compileSdkVersion 31
   ...
   defaultConfig {
      ...
      targetSdkVersion 31
      ...

And I think that was all I did. Let me know if I missed something.

Gradle is connected to Java so check your installed version is 8. If not then get the correct version and try again. ns doctor is your friend!

If that doesn't work, stop any java and emulator (android/qemu) related tasks/processes and try again.

If that fails try rebooting your computer and test again.

Related