Ionic 4 + FCM: How to fix the compiler error - colorAccent not found? - firebase-cloud-messaging

I am working on an Ionic 4 App. I am trying to customize the color of "default_notification_color", but the compiler throws an error. I have the following in my config.xml file:
<meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="#color/orange" />
I have created a new file called "colors.xml" and placed it in the following directory in my project root:
gf > res > values > colors.xml
Here are the contents of colors.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorAccent">#3880ff</color>
    <color name="white">#FFFFFF</color>
    <color name="ivory">#FFFFF0</color>    
    <color name="orange">#FFA500</color>
    <color name="navy">#000080</color>
    <color name="black">#000000</color>
</resources>
I tried to build the app using the following command:
ionic cordova build android --prod 
But it throws me the following error:
BUILD FAILED in 9s
24 actionable tasks: 4 executed, 20 up-to-date
D:\Softwares\wamp\www\gf\platforms\android\gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Android resource linking failed
  D:\Softwares\wamp\www\gf\platforms\android\app\build\intermediates\merged_manifests\debug\AndroidManifest.xml:122: AAPT: error: resource color/orange (aka com.mydomain.myapp:color/orange) not found.
  error: failed processing manifest.
How can this be fixed so that the value is read from the colors.xml file without any issues? 

Ok I figured it out. I had to include the following line in config.xml:
<resource-file src="res/values/colors.xml" target="app/src/main/res/values/colors.xml" />
What this does is essentially it copies the colors.xml
file from the location res/values in the project root, to the location platforms/android/app/src/main/res/values/ folder (considering that you are building this for Android)
It then looks in the colors.xml file for the name "orange" and looks up the corresponding value (i.e. in this case, would be #FFA500) and assigns it as the Notification Icon color.
That's it! So from now on, whenever a notification is received, its color would be equal to the orange color as I indicated in the colors.xml file.
Hope this helps someone.

I ran into the same error while installing the plugin cordova-plugin-firebasex
Just clean the plugins and the platform was built successfully
rm -Rf platforms/android
cordova plugin rm cordova-plugin-firebasex
rm -Rf plugins/ node_modules/
npm install
ionic cordova plugin add cordova-plugin-firebasex
ionic cordova build android
OR
In case you have a problem,
You can rebuild the platform by modifying the following versions:
package.json
"cordova-plugin-firebasex": "^10.2.0-cli", /* VERSION */
"cordova-plugin-firebasex": { /* OPTIONS */
"FIREBASE_ANALYTICS_COLLECTION_ENABLED": "true",
"FIREBASE_PERFORMANCE_COLLECTION_ENABLED": "true",
"FIREBASE_CRASHLYTICS_COLLECTION_ENABLED": "true",
"ANDROID_ICON_ACCENT": "#FF00FFFF",
"ANDROID_PLAY_SERVICES_AUTH_VERSION": "18.0.0",
"ANDROID_FIREBASE_ANALYTICS_VERSION": "17.4.3",
"ANDROID_FIREBASE_MESSAGING_VERSION": "20.2.1",
"ANDROID_FIREBASE_CONFIG_VERSION": "19.1.4",
"ANDROID_FIREBASE_PERF_VERSION": "19.0.7",
"ANDROID_FIREBASE_AUTH_VERSION": "19.3.1",
"ANDROID_FIREBASE_FIRESTORE_VERSION": "21.4.3",
"ANDROID_FIREBASE_CRASHLYTICS_VERSION": "17.0.1",
"ANDROID_FIREBASE_CRASHLYTICS_NDK_VERSION": "17.0.1",
"ANDROID_GSON_VERSION": "2.8.6",
"ANDROID_PLAY_SERVICES_TAGMANAGER_VERSION": "17.0.0",
"ANDROID_FIREBASE_INAPPMESSAGING_VERSION": "19.0.7"
},
"#ionic-native/firebase-x": "^5.29.0", /* */

Related

serve html file from node_modules using react native static server and webview

Is it possible to serve an html file from within the node_modules folder? I know how to serve from the assets folder, something like:
<WebView
...
source={{uri:'file:///android_asset/project_a/index.html'}}/>
or the corresponding path for iOS, but how can I access the node_modules folder and serve a file from there? I've tried using require() and/or using the path to the module I want served but with no luck.
The idea is that, I want to avoid copy-pasting build files between projects (i.e., from the build folder of project A to the assets/www of project B), instead, I want publish project A as an npm package and npm install and serve it from project B. This also improves version management of the projects.
For Android, you can run a custom Gradle task that able to will handle copy your assets in build time.
Create a Gradle file in your module's root, like below:
(I presume your module name is react-native-my-awesome-module and your HTML files is under www folder in module's root.)
awesome.gradle:
/**
* Register HTML asset source folder
*/
android.sourceSets.main.assets.srcDirs += file("$buildDir/intermediates/ReactNativeMyAwesomeModule")
/**
* Task to copy HTML files
*/
afterEvaluate {
def targetDir = "../../node_modules/react-native-my-awesome-module/www";
def fileNames = [ "*.html" ];
def htmlCopyTask = tasks.create(
name: "copyReactNativeMyAwesomeModuleAssets",
type: Copy) {
description = "copy react native my awesome module assets."
into "$buildDir/intermediates/ReactNativeMyAwesomeModule/www"
fileNames.each { fileName ->
from(targetDir) {
include(fileName)
}
}
}
android.applicationVariants.all { def variant ->
def targetName = variant.name.capitalize()
def generateAssetsTask = tasks.findByName("generate${targetName}Assets")
generateAssetsTask.dependsOn(htmlCopyTask)
}
}
After installing the module, put the below line in your project's android/app/build.gradle file:
apply from: file("../../node_modules/react-native-my-awesome-module/awesome.gradle");
When you build your app, your assets under www folder will be copied from your module. You can access your resources in your app like below :
<WebView
source={{uri: 'file:///android_asset/www/index.html'}}
/>
I ended up adding a script to packages.json that copies the files of interest into the assets/www folder before starting the app. Something like:
"scripts": {
"copy:build": "node -e \"fs.copyFileSync('./node_modules/dir-of-module','./assets/www/build')\"",
"start-android": "npm run copyAssets && react-native run-android",
...
}
If there is a better alternative, please let me know!

error building app with hermes: '..' is not recognized as an internal or external command

Building the react-native app on Windows 10.
The error is printed for line 165 of node_modules\react-native\react.gradle:
'..' is not recognized as an internal or external command, operable program or batch file
Line 165 is the 5th line in the following, starting with exec:
if (enableHermes) {
doLast {
def hermesFlags;
def hbcTempFile = file("${jsBundleFile}.hbc")
exec {
if (targetName.toLowerCase().contains("release")) {
// Can't use ?: since that will also substitute valid empty lists
hermesFlags = config.hermesFlagsRelease
if (hermesFlags == null) hermesFlags = ["-O", "-output-source-map"]
} else {
hermesFlags = config.hermesFlagsDebug
if (hermesFlags == null) hermesFlags = []
}
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine("cmd", "/c", getHermesCommand(), "-emit-binary", "-out", hbcTempFile, jsBundleFile, *hermesFlags)
} else {
commandLine(getHermesCommand(), "-emit-binary", "-out", hbcTempFile, jsBundleFile, *hermesFlags)
}
}
ant.move(
file: hbcTempFile,
toFile: jsBundleFile
);
if (hermesFlags.contains("-output-source-map")) {
ant.move(
// Hermes will generate a source map with this exact name
file: "${jsBundleFile}.hbc.map",
tofile: jsCompilerSourceMapFile
);
exec {
// TODO: set task dependencies for caching
// Set up the call to the compose-source-maps script
workingDir(reactRoot)
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine("cmd", "/c", *nodeExecutableAndArgs, composeSourceMapsPath, jsPackagerSourceMapFile, jsCompilerSourceMapFile, "-o", jsOutputSourceMapFile)
} else {
commandLine(*nodeExecutableAndArgs, composeSourceMapsPath, jsPackagerSourceMapFile, jsCompilerSourceMapFile, "-o", jsOutputSourceMapFile)
}
}
}
}
}
Here is the definition of hermescommand in android/app/build.gradle:
project.ext.react = [
enableHermes: true, // clean and rebuild if changing
// next added by Yossi
hermesCommand: "../../node_modules/hermesengine/win64-bin/hermes",
extraPackagerArgs: ["--sourcemap-output", "$buildDir/intermediates/assets/release/index.android.bundle.map"]
]
Which, as far as I understand, points to the following file:
node_modules\hermes-engine\win64-bin\hermes.exe
Any idea?
Updated definition in android/app/build.gradle (following the answer below):
project.ext.react = [
enableHermes: true, // clean and rebuild if changing
// -either- hermesCommand: "..\\..\\node_modules\\hermesengine\\win64-bin\\hermes",
// -or- hermesCommand: "../../node_modules/hermesengine/%OS-BIN%/hermes",
hermesCommand: "../../node_modules/hermesengine/%OS-BIN%/hermes",
extraPackagerArgs: ["--sourcemap-output", "$buildDir/intermediates/assets/release/index.android.bundle.map"]
]
The build output now, after the change, is the following:
> Task :app:bundleReleaseJsAndAssets
warning: the transform cache was reset.
Welcome to React Native!
Learn once, write anywhere
info Writing bundle output to:, C:\esites-grocery\test1\plumpclient\android\app\build\generated\assets\react\release\index.android.bundle
info Writing sourcemap output to:, C:\esites-grocery\test1\plumpclient\android\app\build/intermediates/assets/release/index.android.bundle.map
info Done writing bundle output
info Done writing sourcemap output
info Copying 141 asset files
info Done copying assets
The system cannot find the path specified.
> Task :app:bundleReleaseJsAndAssets FAILED
> Task :app:bundleReleaseJsAndAssets_SentryUpload_3001
Processing react-native sourcemaps for Sentry upload.
> Analyzing 2 sources
> Rewriting sources
> Adding source map references
Uploading sourcemaps for release com.plumpplum#RN62 Hermes+3001 distribution 3001
> Bundled 2 files for upload
> Uploaded release files to Sentry
> File upload complete
Source Map Upload Report
Minified Scripts
~/index.android.bundle (sourcemap at index.android.bundle.map)
Source Maps
~/index.android.bundle.map
> Task :app:bundleReleaseJsAndAssets_SentryUpload_1001
Processing react-native sourcemaps for Sentry upload.
> Analyzing 2 sources
> Rewriting sources
> Adding source map references
Uploading sourcemaps for release com.plumpplum#RN62 Hermes+1001 distribution 1001
> Bundled 2 files for upload
> Uploaded release files to Sentry
> File upload complete
Source Map Upload Report
Minified Scripts
~/index.android.bundle (sourcemap at index.android.bundle.map)
Source Maps
~/index.android.bundle.map
> Task :app:bundleReleaseJsAndAssets_SentryUpload_2001
Processing react-native sourcemaps for Sentry upload.
> Analyzing 2 sources
> Rewriting sources
> Adding source map references
Uploading sourcemaps for release com.plumpplum#RN62 Hermes+2001 distribution 2001
> Bundled 2 files for upload
> Uploaded release files to Sentry
> File upload complete
Source Map Upload Report
Minified Scripts
~/index.android.bundle (sourcemap at index.android.bundle.map)
Source Maps
~/index.android.bundle.map
> Task :app:bundleReleaseJsAndAssets_SentryUpload_4001
Processing react-native sourcemaps for Sentry upload.
> Analyzing 2 sources
> Rewriting sources
> Adding source map references
Uploading sourcemaps for release com.plumpplum#RN62 Hermes+4001 distribution 4001
> Bundled 2 files for upload
> Uploaded release files to Sentry
> File upload complete
Source Map Upload Report
Minified Scripts
~/index.android.bundle (sourcemap at index.android.bundle.map)
Source Maps
~/index.android.bundle.map
FAILURE: Build failed with an exception.
* Where:
Script 'C:\esites-grocery\test1\plumpclient\node_modules\react-native\react.gradle' line: 165
* What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> Process 'command 'cmd'' finished with non-zero exit value 1
Here's more of react.gradle:
def getHermesCommand = {
// If the project specifies a Hermes command, don't second guess it.
if (!hermesCommand.contains("%OS-BIN%")) {
return hermesCommand
}
// Execution on Windows fails with / as separator
return hermesCommand
.replaceAll("%OS-BIN%", getHermesOSBin())
.replace('/' as char, File.separatorChar);
}
You are specifying ../../node_modules/hermesengine/win64-bin/hermes as the path, which is OS specific (as determined by not having an OS placeholder).
As per the comment, react.gradle therefore doesn't second guess your path and just passes it directly to the OS command interpreter.
This fails because your command interpreter does not allow / as directory separator.
Either specify a path that's valid for your system:
hermesCommand: "..\\..\\node_modules\\hermesengine\\win64-bin\\hermes",
Or specify an OS-independent path to let react.gradle transform it for each platform:
hermesCommand: "../../node_modules/hermesengine/%OS-BIN%/hermes",

Cannot Load fontFamily:FontAwesome in reactnative

I'm build app running in react native metro builder but not running because font family font awesome not sync can help me
problem load is : console error : "fontFamily:FontAwesome" is not a system font in reactnative
i am using the fontawesome 5.7.0
just add on your package dependencies:
"react-native-fontawesome": "^5.7.0",
re-install using yarn
yarn install
put the font files on folder
android > app > src > main > assets > fonts
files:
fontawesome-webfont.ttf
FontAwesome.otf
and you can use it on your project:
example:
import FontAwesome, { Icons } from 'react-native-fontawesome';
...
render() {
return (
<FontAwesome>{Icons.close}</FontAwesome>
);
}

React Native Android App with 64k+ methods

I have problem with running RN Android app using react-native run-android
It throws exception at the build stage and can't figure out the issue.
Execution failed for task ':react-native-firebase:transformClassesWithDexForDebugAndroidTest'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
I've tried various solutions on the web and it was all in vein.
Tried solutions were enabling multiDex and increase the javaMaxHeapSize in dexOptions.
This error can be seen as a library or component dependent, but it happens for any kind of apps which exceeds 64k limits.
One more thing:
It compiles without any problem in Android Studio
With react 0.60 I was having this issue, and adding multiDexEnabled true to my defaultConfig (android/app/build.gradle) fixed it:
android {
...
defaultConfig {
...
multiDexEnabled true
}
...
}
You have too many methods by the look of it. This a common DEX issue. As mentioned here:
DexIndexOverflowException issue after updating to latest appcompat and support library
Add this to your build.gradle:
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
Then in your Android Manifest add this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
Let me know if this helps! I have come across this issue before myself.

Error while generating APK react-native

when i try to generate my apk it gave me this error
i tried many solutions and did'nt work out
after i run command:
./gradlew assembleRelease
the error is:
Loading dependency graph, done.
warning: the transform cache was reset.
bundle: start
bundle: finish
bundle: Writing bundle output to: appfolder\android\app\build\intermediates\assets\release\index.andro
id.bundle
 
Don't know which android drawable suffix to use for asset: {"__packager_asset":true,"fileSystemLocation":"appfolder\\src\\public\\images\\icons","httpServerLocation":"/assets/src/public/images/icons","width":12,"height":10,"scales":
[1,2,3,4,5],"files":["appfolder\\src\\public\\images\\icons\\twitter#1x.png","appfolder\\src\\public\\images\\icons\\twitter#2x.png","appfolder\\src\\public\\images
\\icons\\twitter#3x.png","appfolder\\src\\public\\images\\icons\\twitter#4x.png","appfolder\\src\\public\\images\\icons\\twitter#5x.png"],"hash":"aa736287bfea056b34205edd2839d8cc","name":"twitter","
type":"png"}
 
: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
 
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
the error was in assets: i removed #5x
special thanks to #G0dsquad for his comment