Nativescript: runtime exception on tns run - nativescript

When I execute tns run android to test my code, it produces this runtime error:
Gradle build...
+ setting applicationId
+ applying user-defined configuration from C:\Users\Ace\eclipse-workspace\arenamaster\App_Resources\Android\app.gradle
+ using android X library androidx.legacy:legacy-support-v4:1.0.0
+ adding nativescript runtime package dependency: nativescript-optimized-with-inspector
Exception in thread "main" java.lang.RuntimeException: Class not found org.nativescript.widgets.image.Worker.OnImageLoadedListener
at org.nativescript.staticbindinggenerator.Generator.getClass(Generator.java:549)
at org.nativescript.staticbindinggenerator.Generator.getInterfacesFromCache(Generator.java:532)
at org.nativescript.staticbindinggenerator.Generator.writeBinding(Generator.java:283)
at org.nativescript.staticbindinggenerator.Generator.generateBinding(Generator.java:171)
at org.nativescript.staticbindinggenerator.Generator.processRows(Generator.java:234)
at org.nativescript.staticbindinggenerator.Generator.generateBindings(Generator.java:121)
at org.nativescript.staticbindinggenerator.Generator.writeBindings(Generator.java:97)
at org.nativescript.staticbindinggenerator.Main.main(Main.java:53)
I have tried the following:
Deleting my .tns.ts files and reverting code splitting
Migrating the project to androidX
Deleting the platforms directory then running tns run android

nativescript core modules requires a package called nativescript core modules widgets
If you get this error run npm i nativescript-core-modules-widgets

Just noting that with NativeScript 7.x and higher, the answer from #ace zhang is no longer needed. All that's needed is:
"#nativescript/core": "^7.0.0"

Related

Nativescript Angular compiling error "mergeDexDebug"

I am using nativescript v6.4 and angular v8.2 and in project i have install 4-5 plugin and it work fine but after installing one more plugin i.e nativescript-firebase-plugin i got this error when compiling the project.
Execution failed for task ':app:mergeDexDebug'.
Error: null, Cannot fit requested classes in a single dex file (# methods: 132015 > 65536 ; # fields: 77460 > 65536)
Did you go through the documentation of Firebase Plugin?
Adding multiDexEnabled true to your app/App_Resources/Android/app.gradle should solve the issue

Problem with url_launcher package (Flutter)

I’m working on a Flutter project. I’m starting with the counter app. If a use the following packages, I have not any problem:
cupertino_icons: ^0.1.3
flutter_markdown: ^0.3.3
google_fonts: ^0.3.9
google_maps_flutter: ^0.5.23+1
intl: ^0.16.1
provider: ^4.0.4
rive: ^0.0.1
rxdart: ^0.23.1
shared_preferences: ^0.5.6+1
But if I use the url_launcher: ^5.4.1 package, I receive this error:
Launching lib\main.dart on Android SDK built for x86 in debug mode...
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':url_launcher:compileDebugAidl'.
> Could not resolve all task dependencies for configuration ':url_launcher:debugCompileClasspath'.
> Could not resolve androidx.annotation:annotation:1.1.0.
Required by:
project :url_launcher
[...]
How can I solve? Thank you!
With version 5.4.2 of the package the problem seems to be solved.

Android-studio 3.5.1 Gradle ERROR: No value has been specified for property lottie-react-native

Upgraded android studio to 3.5.1. Took fresh checkout of project and gradle sync started failing. Searched everywhere but could not find any proper solution. In logs can see error at line 97 of lottie react native android gradle-maven-push.gradle
Have tried downgrading gradle version, android studio version as well but still same error.
Gradle task defined in gradle-maven-push.gradle
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath()
.join(File.pathSeparator))
}
Got it working by changing the code to
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath()
.join(File.pathSeparator)) + configurations.implementation
}
Reference: https://github.com/airbnb/lottie-android/blob/master/lottie/build.gradle
The difference is that of configuration.implementation between what is downloaded in lottie's react native module's build.gradle and and specified in github link.

Error when trying to run 'gradlew assembleRelease' in the Windows command line : jest-haste-map: Haste module naming collision

I am trying to generate a .apk file of my react native project with the 'gradlew assembleRelease' command. I'm using AWS Amplify, which is where the naming collision seems to be coming from. The version of react native I'm running is 0.59.9.
I've tried creating a 'rn-cli.config.js' file in the root folder and replacing the code in the 'metro.config.js' with the 'rn-cli.config.js' code, which was unsuccessful. I can't remove the problem folder either because that creates more errors.
I've also tried stopping and restarting the Gradle daemon, which hasn't worked either. This is the error I'm getting:
Configure project :app
WARNING: The specified Android SDK Build Tools version (25.0.0) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.4.0.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '25.0.0'" from your build.gradle file, as each version of the Android Gradle Plugin now has a
default version of the build tools.
Task :app:bundleReleaseJsAndAssets
warning: the transform cache was reset.
error jest-haste-map: Haste module naming collision:
Duplicate module name: myreactnativeapp_cfnlambda_ff57ce62
Paths: C:\Users\Kim\Desktop\myReactNativeApp\amplify\backend\interactions\reactLex\src\package.json collides with C:\Users\Kim\Desktop\myReactNativeApp\amplify#current-cloud-backend\interactions\reactLex\src\package.json
This error is caused by hasteImpl returning the same name for different files.. Run CLI with --verbose flag for more details.
Task :app:bundleReleaseJsAndAssets FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
Process 'command 'cmd'' finished with non-zero exit value 1
The code in the 'rn-cli.config.js' file looks like this:
const blacklist = require('metro-config/src/defaults/blacklist');
// blacklist is a function that takes an array of regexes and combines
// them with the default blacklist to return a single regex.
module.exports = {
resolver: {
blacklistRE: blacklist([/amplify\/.*/])
}
};'
Do I need to change the code in the 'rn-cli.config.js' file or is there another workaround I could try?

tns run android with a specific sdk

I just created a new application and added android platform. Since I failed to install API 28 for days, I want to run the project against the working SDK 21. How can I configure the application to run with sdk 21?
My app/App_resources/android/app.gradle is the default one with:
android {
defaultConfig {
generatedDensities = []
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
in platforms/android/.gradle/ I see 4.10.2
while my build.gradle is:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
When i run tns run android --emulator
the message is:
Gradle build...
+ setting applicationId
+ applying user-defined configuration from D:\pyworks\agrigo7\mobileapp\agrigo\app\App_Resources\Android\app.gradle
Using support library version 28.0.0
+ adding nativescript runtime package dependency: nativescript-optimized-with-inspector
+ adding aar plugin dependency: D:\pyworks\agrigo7\mobileapp\agrigo\node_modules\tns-core-modules-widgets\platforms\android\widgets-release.aar
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to find Platform SDK with path: platforms;android-28
In my Android SDK, I tried to install API 28 but it kept on failing and failing. My current SDK looks like:
given API 21 is installed, I tried:
tns run android --compileSdk 21 --emulator
It first does show 28.0.0. then gives a lot of errors:
+ setting applicationId
+ applying user-defined configuration from D:\pyworks\agrigo7\mobileapp\agrigo\app\App_Resources\Android\app.gradle
**Using support library version 28.0.0**
+ adding nativescript runtime package dependency: nativescript-optimized-with-inspector
+ adding aar plugin dependency: D:\pyworks\agrigo7\mobileapp\agrigo\node_modules\tns-core-modules-widgets\platforms\android\widgets-release.aar
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Android resource linking failed
Output: error: resource android:style/TextAppearance.Material.Widget.Button.Borderless.Colored not found.
error: resource android:style/TextAppearance.Material.Widget.Button.Colored not found.
I think you are getting confused between the support library and SDK version. They are different and your support library's major version should always match your SDK's major version which means you can't use support library 28.x with SDK 21.x.
#Jenlooper had given a brief about this breaking change at the 5.0 launch, you must specify the right support library version in the gradle file (project.ext.supportVersion).
Besides, Google Play restricts all new app submissions to target SDK 26 (Android 8.0) so I would recommend you to try SDK 26 instead of 21 which you can't use to publish.

Resources