Android Build Failed, strings/google_app_id duplicate resources error - android

I am working on ionic 4. When I run this command in cmd:
ionic Cordova build android
It gives me a duplicate resource error. I am using firebase and google services.json plugins in my project.
I have tried to remove google_app_id and google_api_key from Andriod.xml file but no change. The same error is displaying again and again. Here is the view of the android.xml file.
Android.xml File
"res/values/strings.xml": {
"parents": {
"/resources": [
// removed google_app_id & google_api_key
]
}
}
}
Strings.xml File:
<resources>
<string name="app_name">UrbanX Driver</string>
<string name="launcher_name">#string/app_name</string>
<string name="activity_name">#string/launcher_name</string>
<string name="google_app_id">#string/google_app_id</string>
<string name="google_api_key">#string/google_api_key</string>
</resources>
Config.xml File:
<resource-file src="google-services.json" target="app/google-services.json" />

Install this plugin cordova-android-play-services-gradle-release:
ionic cordova plugin add cordova-android-play-services-gradle-release
check this link for reason:
https://github.com/arnesson/cordova-plugin-firebase#google-play-services

Related

FirebaseApp initialization unsuccessful

Try using firebase library for Android, followed all the steps in the firebase documents, when I apply the instructions show me in logcat
FirebaseApp initialization unsuccessful.
Images
Who can help , please
I found the answer in The Google Services Gradle Plugin
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="default_web_client_id" translatable="false">1035469437078-e8mr503bun5eaevqctn4u807q4hpi44s.apps.googleusercontent.com</string>
<string name="gcm_defaultSenderId" translatable="false">1035469437078</string>
<string name="firebase_database_url" translatable="false">https://myapp.firebaseio.com</string>
<string name="google_app_id" translatable="false">1:1035469437078:android:73a4fb8297b2cd4f</string>
<string name="google_api_key" translatable="false">AIzaSyFE3G2eN0XZPl-IeEvZhzKOAgC9vy9imVE</string>
<string name="google_storage_bucket" translatable="false">myapp.appspot.com</string>
</resources>
gcm_defaultSenderId:
project_info/project_number
google_app_id:
{YOUR_CLIENT}/client_info/mobilesdk_app_id
google_api_key:
{YOUR_CLIENT}/services/api_key/current_key
google_storage_bucket:
project_info/storage_bucket
firebase_database_url:
project_info/firebase_url
default_web_client_id:
{YOUR_CLIENT}/oauth_client/[first client_type 3]
Make sure you've already inserting google-services-json inside app folder and you have stable internet connection, firebase will perform download package when gradle sync process.

Cannot use strings of resource file in Cordova Android Plugin

I have created a custom plugin for cordova android and I want to use a resource-file. Therefore I have added the following tag to the plugin
<resource-file src="src/android/res/values/strings.xml" target="res/values/strings.xml" />
However, this will lead to the following error when building for android:
TypeError: Cannot set property 'text' of null
at android_parser.update_from_config (C:\Users\Matthias\AppData\Roaming\npm\
node_modules\cordova\node_modules\cordova-lib\src\cordova\metadata\android_parse
r.js:209:51)
ERROR running one or more of the platforms: TypeError: Cannot set property 'text' of null
The build is succesful when I remove the resource-file tag from plugin.xml. Nevertheless, I need those strings.
Does anyone know any solution or alternative to fix this problem? I found a similar problem here, unfortunately without any solution documented:
phonegap build android; not able to build
Thanks.
Have you tried setting strings in your plugin.xml like this:
<config-file target="res/values/strings.xml" parent="/*">
<string name="mystringname">MyStringValue</string>
</config-file>

Phonegap 3 Plugin causing build error or plugin not initialized

Let me start with some context. I have a Java file and a .jar library which contains an Android project with an Activity, its layout, and another jar library. I also have the javascript interface for my plugin, of course. In other words, this is what I have:
plugins/com.phonegap.example.activity.plugin/www/myplugin.js
plugins/com.phonegap.example.activity.plugin/src/android/MyPlugin.java
plugins/com.phonegap.example.activity.plugin/src/android/libs/myJar.jar
plugins/plugin.xml
My plugin is supposed to execute a method within my MyPlugin.java file which is supposed to then launch the Activity that is within the myJar.jar file.
The plugin.xml for this plugin reads:
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
id="com.phonegap.example.activity.plugin"
version="0.1.0">
<name>MyPlugin</name>
<description>Launch an Android Activity from PhoneGap 3</description>
<author>Author</author>
<license>MIT</license>
<keywords>phonegap,activity</keywords>
<js-module src="www/myplugin.js" name="MyPlugin">
<clobbers target="window.MyPlugin" />
</js-module>
<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="MyPlugin">
<param name="android-package" value="com.phonegap.example.activity.plugin"/>
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<activity
android:name="com.phonegap.example.activity.ExampleActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.phonegap.example.action.EXAMPLE" />
</intent-filter>
</activity>
</config-file>
<source-file src="src/android/MyPlugin.java" target-dir="src/com/phonegap/example/activity" />
<source-file src="src/android/libs/myJar.jar" target-dir="libs" />
</platform>
</plugin>
I have installed Phonegap 3.3 and Cordova 3.4 using npm install, and I have Ruby 2.0.0 installed as well. I'm running all this on a Mac OS X.
Onto the problem:
I create a phonegap app to test this plugin (phonegap create TestApp)
I add the Android platform (cordova platform add android)
I run phonegap local plugin add /path/to/plugin/folder from within my newly created app
I run phonegap build android and the compile fails with the following error:
[error] An error occurred while building the android project. Error executing "ant debug -f "/path/to/TestApp/platforms/android/build.xml"":
BUILD FAIL
/path/to/ant/build.xml:720: The following error occurred while executing this line:
/path/to/ant/build.xml:734: Compile failed; see the compiler error output for details.
Total time: 4 seconds
I don't understand why this is happening at all. When I install the plugin it seems like it's been added successfully and it appears within the plugins/android.json file.
At one point, the project automagically decided to compile properly (I don't know what made it work). I tried to access the plugin I had added by adding a line that reads var p = window.MyPlugin within the www/js/index.js, right after the app.receivedEvent('deviceready'); in the onDeviceReady function. I used console.log(p); and it turned out to be undefined, as if my plugin had never been loaded/initialized in the first place.
I suppose this is a problem within my plugin definition, since the Java part has been tested on an Android native app and it was working properly. Where did I go wrong with my plugin? What can I do to troubleshoot it? Why wasn't it initialized? Any help/guidance is very well-appreciated.
======UPDATE=====
I followed Dawson's suggestion to use cordova build android -d and here's the output I received:
[javac] /path/to/TestApp/platforms/android/src/com/phonegap/example/MyPlugin.java:10:
error: package com.phonegap.example.activity does not exist
[javac] import com.phonegap.example.activity.ExampleActivity;
This com.phonegap.example.activity package is defined within the myJar.jar file, so it seems that MyPlugin.java can't find the myJar.jar file.
I think the plugin.xml should be correctly taking care of the including the jar file during plugin installation. This is how it's being added in the plugin.xml:
<source-file src="src/android/libs/myJar.jar" target-dir="libs" />
Any ideas of what may be wrong here?
It's solved thanks to Dawson.
I ran cordova build android -d and viewed its output. Noticed misplaced libraries (myPlugin.java couldn't find myJar.jar) so I just moved them to the proper place as Dawson suggested.
Thanks a lot!

Android Phonegap plugin and google analytics

I am using phonegap plugin and I could not get it to work. In the plugin, there is a plugin.xml and may I know how this file should be set up.
I have mine configured as below and it does not work.
<platform name="android">
<config-file target="res/xml/config.xml" parent="plugins">
<feature name="GAPlugin" >
<param name="android-package" value="com.adobe.plugins.GAPlugin"/>
</feature>
</config-file>
<source-file src="src/com/learnchn/pinyin/GAPlugin.java"
target-dir="src/com/learnchn/pinyin" />
<source-file src="libs/libGoogleAnalyticsV2.jar"
target-dir="libs" />
</platform>
plugin.xml is a file that is meant to be read and executed by tools such as the plugman to install a plugin to a platform. If you are not using such a tool then you may try to do the steps manually. Basically insert <feature> to res/xml/config.xml and copy src files on <source-file> to target-dir.
However I doubt that the plugin.xml you have posted is valid. The value for "android-package" parameter should point to the plugin implementation. The value "com.adobe.plugins.GAPlugin" would suggest that there would be a corresponding source file or a library with that class name added as part of the installation. However the only file that is added with a close name is "com/learnchn/pinyin/GAPlugin.java" which has a different package name.
At first you have to build your project with phonegap. Navigate to the location where you want to create your project and do the following:
phonegap create test com.example.test Test
cd test
phonegap local build android
Now you have a working android project in your "platforms/android/" directory which you can import in eclipse. Download the GAPlugin and unzip it. Then just use plugman to install the Google Analytics Plugin.
plugman install --platform android --project (Path to your phonegap android project) --plugin (path to the GAPlugin)
Now everything should be set and the plugin is installed. The next step would be initializing the plugin in your index.html to track every page visit. Add the GAPlugin.js
<script type="text/javascript" src="GAPlugin.js"></script>
You should add the following code after you received the "deviceready" event.
document.addEventListener("deviceready", onDeviceReady, false);
var gaPlugin;
function onDeviceReady() {
gaPlugin = window.plugins.gaPlugin;
gaPlugin.init(successHandler, errorHandler, "UA-********-*", 10);
// Put this function everywhere you want to track something
gaPlugin.trackPage( nativePluginResultHandler, nativePluginErrorHandler, "index.html");
function successHandler() {}
function errorHandler() {}
function nativePluginResultHandler() {}
function nativePluginErrorHandler() {}
}
This approach worked for me. I'm using Phonegap 3.0 with the CLI.
Hope this fixes your problems ;)
If u want to add simple google Analytics setup then its quite easy just follow the below steps
1:- Add libGoogleAnalyticsV2.jar in libs folder 2:- Add analytics.xml file inside res->values, it binds the trackingid with the app,u can google for this file 3:-Add import com.google.analytics.tracking.android.easyTracker; in the activity file and use EasyTracker.getInstance().activityStart(this); in onCreate function.
Thats it, you are done with Google Analytics basic setup

Compiling error with Android Phonegap app

I'm using Phonegap and Barcode Scanner plugin. I'm trying to build an test application. I'm following below tutorial.
http://www.mobiledevelopersolutions.com/home/start/twominutetutorials/tmt3
I have paste the BarcodeScanner.java to the correct path, as you see in the image.
But when compiling following error happens:
Android Packager: [phonegapbarcode] C:\Users\achintha_s\IdeaProjects\Barcode PhoneGap\AndroidManifest.xml:59: error: Error: No resource found that matches the given name (at 'label' with value '#string/share_name').
How can I solve this? I'm using IntelliJ Studio.
Check the strings.xml in values folder of res folder whether there is a string with name share_name as below:
<string name="share_name">My App Name</string>
and the strings.xml file should like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="share_name">My app Name</string>
</resources>
Make sur you've a stringname share_name in your String.xml file.
<string name="share_name">My App</string>

Categories

Resources