Firebase Notification does not work with experimental gradle - firebase-notifications

Fire Base messaging stops working with experimental gradle.
How to recreate the issue
Create a project to support firebase notifications
follow
https://firebase.google.com/docs/notifications/android/console-audience
Build and run. Works wonderfully well
Change the gradle to experimental build. Follow steps in Hello Jni example to change to experimental gradle. Forget adding C code for now just make the changes to support experimental gradle. Follow
https://codelabs.developers.google.com/codelabs/android-studio-jni/index.html?index=..%2F..%2Findex#0
Build and Run: Firebase cannot initialise any longer. See logs and search for firebase which indicate Firebase initialisation unsuccessful :(
Gradle version (File -> Project Structure, Project): 2.10
Android Plugin Version (File -> Project Structure, Project): None
SDK Version: “Android SDK Tools” Rev. (Tools -> Android -> SDK Manager) : 25.1.7
Module Compile Sdk Version (File -> Project Structure, Your Module): 24.0.0
Module Build Tools Version (File -> Project Structure, Your Module): 24.0.0
Any workaround please.
Thanks in advance
Thanks and Regards,
PB

I also faced the same problem and spend several days investigating and googling. The problem is that Google Services Gradle Plugin isn't compatible with gradle-experimental. However digging deeper I found out that this plugin doesn't do a lot, it just parses "google-services.json" and generates "app/build/generated/res/google-services/{build_type}/values/values.xml" out of it.
So I just manually generated that file "MyProject/src/main/res/values/google-services.xml"
<?xml version="1.0" encoding="utf-8"?>
<resources>
<! -- Present in all applications -->
<string name="google_app_id" translatable="false">1:1035469437089:android:73a4fb8297b2cd4f</string>
<! -- Present in applications with the appropriate services configured -->
<string name="gcm_defaultSenderId" translatable="false">1035469437089</string>
<string name="default_web_client_id" translatable="false">337894902146-e4uksm38sne0bqrj6uvkbo4oiu4hvigl.apps.googleusercontent.com</string>
<string name="ga_trackingId" translatable="false">UA-65557217-3</string>
<string name="firebase_database_url" translatable="false">https://example-url.firebaseio.com</string>
<string name="google_api_key" translatable="false">AIzbSyCILMsOuUKwN3qhtxrPq7FFemDJUAXTyZ8</string>
<string name="google_crash_reporting_api_key" translatable="false">AIzbSyCILMsOuUKwN3qhtxrPq7FFemDJUAXTyZ8</string>
</resources>
More info can be found: https://developers.google.com/android/guides/google-services-plugin
Hope this helps.

Just to add to xp-vit's answer (which was incredibly helpful to me) you can add another android client to your firebase project that doesn't use the experimental gradle to generate the XML for you and then you only have to change the "google_app_id" field. This is found under the {YOUR_CLIENT}/client_info/mobilesdk_app_id in the json file.
Might help avoid typos.

Faced the same issue. And it's a hard bug. You don't know that your Firebase events are not being sent until you turn Firebase log into Verbose mode.
For those who doesn't know how to enable Firebase logs:
In AndroidStudio in Terminal window execute the following:
adb shell setprop log.tag.FA VERBOSE
adb shell setprop log.tag.FA-SVC VERBOSE
adb logcat -v time -s FA FA-SVC
Thanks to that I found an error:
Missing google_app_id. Firebase Analytics disabled
I've double checked everything but then I found a ticket in Android bug tracker saying that experimental gradle interferes with Firebase Analytics.
In order to resolve this I've migrated from 'com.android.tools.build:gradle-experimental:0.8.3' to the latest stable regular Gradle plugin 'com.android.tools.build:gradle:2.2.3'.
And everything works like a charm.
So this is how you migrate from experimental gradle plugin to the latest stable plugin v. 2.2.3:
1. Update your gradle scripts.
http://tools.android.com/tech-docs/new-build-system/gradle-experimental/migrate-to-stable In this article after you install everything in sdk mnager you need to do the following:
In your project-level build.gradle file, change the classpath dependency of the gradle plugin to 2.2.0 or higher
buildscript {
repositories {...}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
Switch to Stable Gradle DSL
You only need to follow the instructions in this section of the guide if you are migrating from experimental Gradle. Since the stable version of Gradle does not use the component model mechanism, you need to change some of the DSL in your module-level build.gradle file:
At the top of your module-level build.gradle file, you need to apply the stable version of the plugin as follows:
apply plugin: 'com.android.application'
- also if you have any modules - the first line for them should be the following: apply plugin: 'com.android.library'
Remove the model{} block, including its opening and closing curly braces. The android{} block should not be enclosed within any other DSL elements.
Remove “.apiLevel” suffix from minSdkVersion and targetSdkVerion:
minSdkVersion 16
targetSdkVersion 23
Change the proguardFiles DSL to the following:
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
Remove create(“...”) from your productFlavor configurations. For example, use the following DSL to create a “flavor1” product flavor:
-I didn't have those
productFlavors {
flavor1 {
applicationId “com.app”
}
...
}
Only define abiFilters in the ndk{} block--comment out everything else in this block. The stable plugin uses a new externalNativeBuild{} DSL to link Gradle to your CMake or ndk-build project, and set toolchain arguments and compiler flags.
- here I commented out entire ndk{} block
2. Create a CMake build script. Easy
https://developer.android.com/studio/projects/add-native-code.html#create-cmake-script
Do exact how it is told here. Right click on our model in right Project side window. New file. Create it. Paste it. I had only one C++ class so I have a very simple CMakeLists.txt file:
cmake_minimum_required(VERSION 3.4.1)
add_library(
lib-name
SHARED
my_cpp_class.cpp )
3. Link C++ Project with Gradle
Open the Project pane from the left side of the IDE and select the Android view.
Right-click on the module you would like to link to your native library, such as the app module, and select Link C++ Project with Gradle from the menu. You should see a dialog similar to the one shown below
From the drop-down menu, select either CMake or ndk-build.
If you select CMake, use the field next to Project Path to specify the CMakeLists.txt script file for your external CMake project.
! Important: if you have any other modules - do these steps for every module in your project !
And that's it. Clean your project and build it again.
Now you can use Firebase Analytics.
Basically I didn't create or told anything new, so all credits to Google.
I just put together two articles of how to do it and wrote down the steps with my comments.
It's not hard and it will give you more benefits because experimental gradle may cause some problems anytime in the future.

Related

Setting up a Rascal example project

How do I setup a Rascal-MPL project to consume the DSL built with Rascal?
I don't seem to find any resource that details how to solve that particular problem
The documentation hasn't been written for that case but here goes:
Use newRascalProject from util::Reflective to create a basic setup. For both the DSL project and the consuming project that makes sense.
mvn install in the DSL project, if you won't have the DSL project folder open in Eclipse or VScode or if you are working bare bones Unix/Maven.
In RASCAL.MF of the client project add Require-Libraries: |lib://dsl-project|
In pom.xml of the client project add a dependency on the DSL jar.
Restart the console or terminal for a file of the client project.
In the terminal the active version of the path configuration for the interpreter will be printed. It should have the DSL project in the list of srcs.
In VScode log for the Rascal LSP you can see the path configuration printed when compiling/checking source files in the client project. There the DSL project should be in the libs path.
If the DSL project isn't compiled to .tpl files that appear in the target folder and eventually in the jar, you will get spurious error messages in the client code. In that case trigger the compiler in the DSL project by saving the top module, or run mvn install again. Revisit the pom file for the settings of the rascal-maven-plugin
For those landing at this page and trying to find an example of calling newRascalProject with working parameters...
The first parameter is a 'location'. While it is documented how to use this parameter (https://www.rascal-mpl.org/docs/Rascal/Expressions/Values/Location/), it still took my some time to figure out that a location is not a regular string, and not using double quotes " but |.
So if you try:
newRascalProject ("home:///Projects/rascal_playground", "hello2")
You get the following error:
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/UndeclaredVariable/UndeclaredVariable.html|
Including the variable name for the 2nd parameter...
newRascalProject ("home:///Projects/rascal_playground", name="hello")
... gives the same error.
This is the correct example:
newRascalProject (|home:///Projects/rascal_playground|, name="hello")

intellij grails unable to resolve external library at groovy compile time

I'm writing a simple etrade programmatic trading program that needs to authenticate with etrade oauth. I'm using IntelliJ Ultimate with Grails 3.1.9.
I added a folder full of jars to Project Settings->Libraries and Project Settings->Modules->main project (accessible by pressing "command ;") and selected "export." The classes resolve fine in the groovy editor in my controller class but they don't resolve at groovy compile time. Why is that?
~/IdeaProjects/<project name>/grails-app/controllers/etradescripter/ETradeUserController.groovy: 8: unable to resolve class com.etrade.etws.sdk.client.ClientRequest
# line 8, column 1.
import com.etrade.etws.sdk.client.ClientRequest;
Grails use the Gradle build system, which is comparable (superior IMHO) to maven.
It is completely external to the IDE itself and not dependend to any IDE.
It is a very powerfull external build tool which has it's own tooling, dependency management,
library cache and logs.
The libraries and SDK you declare in Intellij project structure settings are for IntelliJ internal support (intellisense, code assist, decompiling etc) not for building and/or debugging
The gradle tooling support for your project (found in File/Settings/Gradle) can be:
a gradlew declaration in the project : the project will use it's own
build system version downloaded from the specifications in
gradle/wrapper/gradle-wrapper.properties file with the accompanying
gradle-wrapper.jar downloader - this is the recommended way to go if you are not comfortable with the system to avoid
problems but disk consuming and not the fastest build. There will be a gradle binary distribution download for the first build
a Gradle version bundled with Intellij (2.13 for the last IntelliJ version I think)
one you can declare in the project settings (ie your own Gradle installation root, you have to install it before and set the right
environment variables to make it work) for the last one it can be a
"daemon" version which speeds up thing notably but is very cpu and
memory expensive for a large project (be prepared for 100% cpu and
memory hogs for a large project whatever computer you have).
The main file for build where you declare the build and debug dependencies is "Build.gradle" file at the root of your project.
Dependencies are declared with lines (Groovy syntax, gradle is a groovy tool) like:
dependencies {
assets "com.craigburke.angular:angular-template-asset-pipeline:2.2.6"
assets "com.craigburke.angular:angular-annotate-asset-pipeline:2.4.0"
assets "com.craigburke:js-closure-wrap-asset-pipeline:1.2.0"
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
etc...
This is where you have to add your own dependencies, not in IntelliJ SDK/lib settings.
This is comparable to the maven system with a different syntax (groovy).
For jars comming from an external repo or local dependencies, you should see lines that you can copy/paste and modify.
If not look at gradle docs
especially 23.3 and 23.4, how to declare you dependencies.
There can be other gradle files in gradle directory and/or subprojects directory. It depend on your project.
To build your project, you can open the Gradle tool window in IntelliJ (View/Tool Windows/Gradle), select the build task (Task/build/build), double click on it and it will launch the build.
This will change the run/debug configuration in the IntelliJ IDE so you can build it again with the IDE toolbar by clicking on the Run button
Note: the run button runs the currently selected gradle task, not the application, this is a bit confusing at the beginning
To run or debug you app, you select the appropriate task, in case of Grails task, application/bootrun and double click on it.
This will launch your application (after a build if needed), and if it is a web app, you can browse you application in your browser.
When you run the Run task (not the build task) you can also click on 'Debug' icon to debug your application
If you select another task and click debug, you will have a socket exception because IntelliJ thinks you are launching a jvm and tries to connect to it for debugging.
(they are lots of predefined task in Gradle : assembling jars, building docs etc... and the Run task may be specific to a project
Generally Build tasks are under the build category and run task under the application category)

Errors in Eclipse (Spring Tool Suite) in Spring Security

I'm attempting to become a contributor for Spring Security, it's not going so well. I am getting validation errors in Spring Tool Suite although the build/compilation of the .gradle project is succeeding. The errors show up in the "Markers" view in Eclipse. Here is what I've done so far.
Forked the Spring Security master branch on Github
Copied the https URL for my forked branch
In Spring Tool Suite, Import->Git->Projects from Git->Clone URI
After #3 Spring Tool Suite downloaded the project from Git
Spring Tool Suite prompted asking me what type of project to create
I selected "Import as a general project"
I deleted the project from my workspace (but did not delete it on disk)
I imported the project using Import->Gradle->Gradle project and the recommended settings
After everything finishes building, I get the following error in Spring Tool Suite:
The error is accompanied by several messages including the following:
Pointcut cannot be resolved to a type
The method aspectOf() is undefined for the type ...
The method proceed() is undefined for the type ...
This error can be fixed (with an ugly hack) if I open the Eclipse .project file and add the following:
<buildSpec>
<buildCommand>
<name>org.eclipse.ajdt.core.ajbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.ajdt.ui.ajnature</nature>
</natures>
Question
How can I properly set up my development environment? What should I look into for figuring out why I'm getting these errors? I'm currently researching how the gradle/maven configurations relate to the Eclipse .project file, but I have not gotten very far yet.
Here is what works for me (and what I discussed with Rob Winch):
download STS 3.7.2 (not the latest 3.7.3, it has a few issues when importing spring-security projects) from https://spring.io/tools/sts/all. There is a link to previous versions of STS. There you find STS 3.7.2.
install Groovy-Eclipse into that from here: http://dist.springsource.org/snapshot/GRECLIPSE/e4.5/
install the Gradle STS tooling from here:
http://download.springsource.com/release/TOOLS/update/3.7.2.RELEASE/e4.5
after installing all the components mentioned above, import the spring-security projects using the STS Gradle support ("Import -> Gradle -> ...")
it might take a while, but after downloading the necessary artifacts, all those projects should appear in your workspace. The "aspects" one has an error marker on it. Right-click on the project, go to the Groovy context menu entry, and do the "remove Groovy nature" (or something like that). That removes the groovy tooling for that project and it compiles fine.
After all those steps, I get a workspace with all those projects compiling fine. But it looks like we could/should simplify this procedure in the future using an Eclipse Oomph setup file maybe. But that is a story for the future.
Hope this helps!!!
I found this walkthrough on how to bring spring projects into eclipse via gradle. It actually looks like it was based on Spring Security which might create a nice process flow for you.
My guess is, eclipse is not defaulting to use the gradle configuration for its dependency management.

How do I install Rascal

Can someone tell me how to install Rascal?
The install instruction say - Eclipse Indigo for RCP/RAP - got it.
Then Install New Software and put in the repository address:
http://update.rascal-mpl.org/stable/
- done that
Check "Contact all update sites during install to find required software" - ok
Hit Next, and it complains can't find Jetty, so set up its repo, can't find some Http lib, and on it goes.
What I have done, after I temporarily gave up on Eclipse, is to compile using the Maven build.
This makes me think, is a dependency missing from the Developer Dependencies list? That being the 'rascal-master' project, which contains not much more than the top-level pom.xml file?
I downloaded that too, and tried to build. It did not work because Tycho could not resolve dependencies correctly, it ended up looking for pdb.values:0.0.0 instead of the correct version, I don't know how it managed to zero out the version.
I notice that there is a Jenkins build server, which presumably runs off the Maven poms? It might be an idea to update the Developer Dependencies page with an accurate list of what needs checked out to build from scratch with Maven. It should be as easy as check out some projects, then type 'mvn install' and it all works nicely. Perhaps that is already the case on the build server, but I can't get into the configurations to see how that works.
In the end I removed Tycho from the build, and found enough dependencies in the Maven central repo by hand to get it building, and just put in statements for each of them.
It really is a sad state of affairs the way that Eclipse disrespects the Maven repository, by creating their own and using their own format and tool; Tycho will not download stuff from Eclipse and put it in your local repository, from where you could use it in a more sane way.
The installation instructions seems to be outdated. I can confirm that Rascal will not install with Eclipse Indigo due to dependency errors. It works fine with Eclipse Juno for RCP/RAP.
Ouch, that's a painfull experience, it should not have been this hard, I will look into this.
As workaround: see Rascal Developer dependencies , if you install these dependencies by hand, it should work.
If you continue experiencing installation problems, leave a Github issue, since that is more suited for back and forward conversations.
To use Maven, you also need to insert the following into the pom.xml of rascal-master (replacing the old modules section if there is one):
<modules>
<module>../pdb</module>
<module>../pdb.ui</module>
<module>../pdb.values</module>
<module>../imp.runtime</module>
<module>../imp.pom</module>
<module>../ambidexter</module>
<module>../rascal</module>
<module>../rascal-eclipse</module>
<module>../rascal-shell</module>
<module>../rascal-feature</module>
<module>../rascal-update-site</module>
</modules>
Then run "mvn clean install" or "mvn clean install -DskipTests=true" from inside rascal-master.

ant-metricstask.jar

Warning : since version 1.3.6 the anttask.jar as been renamed ant-metricstask.jar
As of version 1.3.2 the metrics plugin contains some ant tasks that can be used for headless operations as part of a nightly build for example. This section describes how to do this.
Where can i get it? I can not find it anywhere.
Are you looking for ant-metricstask.jar?
It's available in the eclipse plugin downloadable at
http://sourceforge.net/projects/metrics/files/
Point eclipse directly at the URL or download the updatesite_1.3.6.zip and you can get the jar inside.

Resources