GoogleAnalytics Error


#1

ionic 3.20.0
Cannot find a complete code example of GoogleAnalytics implementation, Which can work on current version of ionic and typescript.

tried (1): https://www.thepolyglotdeveloper.com/2016/03/use-google-analytics-in-an-ionic-2-android-and-ios-app/ (this one is outdated)

tried (2): https://stackoverflow.com/questions/38104609/error-implementing-google-analytics-into-ionic-2 (this one also looks outdated)

tried (3): https://github.com/danwilson/google-analytics-plugin returning error during build

Now build returning error.

Error Details:

D:\mypath1>ionic cordova build android --prod --release
Running app-scripts build: --prod --platform android --target cordova
[05:59:12]  build prod started ...
[05:59:12]  clean started ...
[05:59:12]  clean finished in 2 ms
[05:59:12]  copy started ...
[05:59:12]  deeplinks started ...
[05:59:12]  deeplinks finished in 69 ms
[05:59:12]  ngc started ...
Warning: Can't resolve all parameters for WebAudioTrack in D:/mypath1/node_mod
ules/ionic-audio/dist/ionic-audio-web-track.d.ts: (?, ?). This will become an er
ror in Angular v6.x
Warning: Can't resolve all parameters for WebAudioTrack in D:/mypath1/node_mod
ules/ionic-audio/dist/ionic-audio-web-track.d.ts: (?, ?). This will become an er
ror in Angular v6.x
Warning: Can't resolve all parameters for CordovaAudioTrack in D:/mypath1/node
_modules/ionic-audio/dist/ionic-audio-cordova-track.d.ts: (?). This will become
an error in Angular v6.x
Warning: Can't resolve all parameters for CordovaAudioTrack in D:/mypath1/node
_modules/ionic-audio/dist/ionic-audio-cordova-track.d.ts: (?). This will become
an error in Angular v6.x
[05:59:20]  ngc finished in 7.66 s
[05:59:20]  preprocess started ...
[05:59:20]  preprocess finished in 1 ms
[05:59:20]  webpack started ...
[05:59:20]  copy finished in 7.92 s
[06:00:47]  webpack finished in 86.88 s
[06:00:47]  uglify started ...
[06:00:47]  sass started ...
Without `from` option PostCSS could generate wrong source map and will not find
Browserslist config. Set it to CSS file path or to `undefined` to prevent this w
arning.
[06:00:48]  sass finished in 937 ms
[06:00:48]  cleancss started ...
[06:00:49]  cleancss finished in 1.45 s
[06:01:00]  uglify finished in 13.71 s
[06:01:00]  postprocess started ...
[06:01:00]  postprocess finished in 9 ms
[06:01:00]  lint started ...
[06:01:00]  build prod finished in 108.49 s
> cordova build android --release
Android Studio project detected

ANDROID_HOME=C:\Users\Am\AppData\Local\Android\Sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_144
studio
Subproject Path: CordovaLib
Subproject Path: app
publishNonDefault is deprecated and has no effect anymore. All variants are now
published.

The Task.leftShift(Closure) method has been deprecated and is scheduled to be re
moved in Gradle 5.0. Please use Task.doLast(Action) instead.

        at build_3y3zvrqrgo7sxddbenvng1nq5.run(D:\mypath1\platforms\android\ap
p\build.gradle:144)

Configuration 'compile' in project ':app' is deprecated. Use 'implementation' in
stead.


FAILURE: Build failed with an exception.

* Where:
Script 'D:\mypath1\platforms\android\cordova-support-google-services\qqq-bui
ld.gradle' line: 16

* What went wrong:
A problem occurred evaluating project ':app'.
>
Failed to apply plugin [class 'com.google.gms.googleservices.GoogleServicesPlugi
n']
   > For input string: "+"

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.

* Get more help at https://help.gradle.org


BUILD FAILED in 0s
(node:10348) UnhandledPromiseRejectionWarning: Error: cmd: Command failed with e
xit code 1 Error output:
FAILURE: Build failed with an exception.

* Where:
Script 'D:\mypath1\platforms\android\cordova-support-google-services\qqq-bui
ld.gradle' line: 16

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [class 'com.google.gms.googleservices.GoogleServicesPlu
gin']
   > For input string: "+"

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
    at ChildProcess.whenDone (D:\mypath1\platforms\android\cordova\node_module
s\cordova-common\src\superspawn.js:169:23)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
(node:10348) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This
 error originated either by throwing inside of an async function without a catch
 block, or by rejecting a promise which was not handled with .catch(). (rejectio
n id: 1)
(node:10348) [DEP0018] DeprecationWarning: Unhandled promise rejections are depr
ecated. In the future, promise rejections that are not handled will terminate th
e Node.js process with a non-zero exit code.
[06:01:03]  lint finished in 2.35 s


D:\mypath1>

Where can I find the exact version number for “com.android.tools.build:gradle”?


#2

That’s your problem. You will have to correct that manually to your project. To do so, go in your android platform in project.properties (if you use cordova-android >= 7) or just find the following property

play-services-analytics:+

then change the :+ to the FCM version you use. for example, I use push plugin which use FCM 11.6.2, so I replaced + with 11.6.2

I would also suggest to make the same change in plugins/cordova-plugins-google-analytics/plugin.xml otherwise each time you will remove/add your platform again you would have to do the modification in the platform again


#3

Thank you @reedrichards
Yes. Cordova Platforms : android 7.0.0

As I asked…

I already assume that, the “+” is the problem. But what should I replace with. I tried multiple strings, no luck.

I don’t use push plugin. anyway.
How can I make sure that, the “11.6.2” or which one is appropriate value for “play-services-analytics” in my case?


#4

In platforms/android/project.properties is there any other numbers than :+ which are used has references (like :11.6.2) to FCM? If yes, maybe use the same?

Otherwise maybe you could search the keywords play-services on the all platform and see if you find the version number

But these are guesses


#5

I followed your instruction @reedrichards, Now the error is:

...
[06:39:20]  lint finished in 2.54 s
Could not find google-services.json while looking in [src/nullnull/debug, src/de
bug/nullnull, src/nullnull, src/debug, src/nullnullDebug]

registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollec
tion)
Could not find google-services.json while looking in [src/nullnull/release, src/
release/nullnull, src/nullnull, src/release, src/nullnullRelease]
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollec
tion)
:CordovaLib:preBuild UP-TO-DATE
:CordovaLib:preReleaseBuild UP-TO-DATE
:CordovaLib:compileReleaseAidl

:CordovaLib:compileReleaseRenderscript

:CordovaLib:checkReleaseManifest
:CordovaLib:generateReleaseBuildConfig

:CordovaLib:prepareLintJar UP-TO-DATE
:CordovaLib:generateReleaseResValues
:CordovaLib:generateReleaseResources
:CordovaLib:packageReleaseResources

:CordovaLib:platformAttrExtractor

:CordovaLib:processReleaseManifest

:CordovaLib:javaPreCompileRelease

:CordovaLib:processReleaseJavaRes
 NO-SOURCE
:app:preBuild UP-TO-DATE
:app:preReleaseBuild

:app:compileReleaseAidl

:CordovaLib:packageReleaseRenderscript NO-SOURCE
:app:compileReleaseRenderscript

:app:checkReleaseManifest
:app:generateReleaseBuildConfig
:app:prepareLintJar UP-TO-DATE
:app:generateReleaseResValues

:app:generateReleaseResources
:CordovaLib:processReleaseResources

:CordovaLib:generateReleaseSources

:CordovaLib:compileReleaseJavaWithJavac
Note: Some input files use or override a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

:CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForRelease

:app:processReleaseGoogleServices FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processReleaseGoogleServices'.
> File google-services.json is missing. The Google Services Plugin cannot functi
on without it.
   Searched Location:
  D:\mypath1\platforms\android\app\src\nullnull\release\google-services.json
  D:\mypath1\platforms\android\app\src\release\nullnull\google-services.json
  D:\mypath1\platforms\android\app\src\nullnull\google-services.json
  D:\mypath1\platforms\android\app\src\release\google-services.json
  D:\mypath1\platforms\android\app\src\nullnullRelease\google-services.json
  D:\mypath1\platforms\android\app\google-services.json

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
21 actionable tasks: 19 executed, 2 up-to-date
(node:5688) UnhandledPromiseRejectionWarning: Error: cmd: Command failed with ex
it code 1 Error output:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processReleaseGoogleServices'.
> File google-services.json is missing. The Google Services Plugin cannot functi
on without it.
   Searched Location:
  D:\mypath1\platforms\android\app\src\nullnull\release\google-services.json
  D:\mypath1\platforms\android\app\src\release\nullnull\google-services.json
  D:\mypath1\platforms\android\app\src\nullnull\google-services.json
  D:\mypath1\platforms\android\app\src\release\google-services.json
  D:\mypath1\platforms\android\app\src\nullnullRelease\google-services.json
  D:\mypath1\platforms\android\app\google-services.json

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
    at ChildProcess.whenDone (D:\mypath1\platforms\android\cordova\node_module
s\cordova-common\src\superspawn.js:169:23)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
(node:5688) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This
error originated either by throwing inside of an async function without a catch
block, or by rejecting a promise which was not handled with .catch(). (rejection
 id: 1)
(node:5688) [DEP0018] DeprecationWarning: Unhandled promise rejections are depre
cated. In the future, promise rejections that are not handled will terminate the
 Node.js process with a non-zero exit code.


D:\mypath1>

#6

No idea but if you google the subject or search the forum you will find a couple of references to this error, like File google-services.json is missing