Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only Android Application Modules can be connected to Firebase online projects

In Android Studio 3.2.1 I select:
New flutter Application, I then enter
Application Name: sample_firebase_app
I Select Next and the application is created in:
D:\Flutter\SampleFirebaseApplication

A new Flutter application for Firebase Company Name: mycompanyname.com I Include kotlin support but No Swift Support, it produces the main.dart

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(

Project ID: homeassistantmobile

On the Firebase website I create a new project:
HomeAssistantMobile

I then select the option to add a firebase application
I add the application ID from my build.gradle
com.mycompanyname.samplefirebaseapp

I register the application
It then offers me the option of downloading the google-services.json

The firebase website shows this going in the location:
My-Application/app But I don't have that file structure so I put it in D:\Flutter\SampleFirebaseApplication\sample_firebase_app\android\app

The firebase site then suggests adding the following to the Project-level build.gradle (/build.gradle):

buildscript {
  dependencies {
    // Add this line
    classpath 'com.google.gms:google-services:4.0.1'
  }
}

But there is no such path, so I put it in D:\Flutter\SampleFirebaseApplication\sample_firebase_app\android\build.gradle

The firebase site then suggests to put the text below into App-level build.gradle (//build.gradle):

dependencies {
  // Add this line
  implementation 'com.google.firebase:firebase-core:16.0.1'
}
...
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'

However there is path corresponding to this so I put it in

D:\Flutter\SampleFirebaseApplication\sample_firebase_app\android\app\build.gradle

It then suggests to sync by : "Finally, press "Sync now" in the bar that appears in the IDE:" No such message appears, so I right click the gradle files and select sync

I see an error Assertion failed: Write access is allowed inside write-action only (see com.intellij.openapi.application.Application.runWriteAction())

But eventually the app runs but the firebase webpage is stuck at:
Run your app to verify installation:
Checking if the app has communicated with our servers. You may need to uninstall and reinstall your app.

After a lifetime of waiting I hit: Skip this step

I uninstall and try again Same Result

Approach Number two
I select Tools->firebaseThe assistant pops up
I select: Set up firebase cloud messaging
I am greeted with:
Firebase Cloud Messaging lets you receive and send messages from your app to the server and other clients. This tutorial explains how to set up FCM and enable your app to receive notifications.
I select the first option:
Connect to Firebase
I am greeted with:
Could not find the Android Application module. Only Android Application Modules can be connected to Firebase online projects. Create a new Android Application Module or create/import a different Android Studio project.

I have tried numerous other approaches, followed tutorials and spent many hours on this and have made no progress, any suggestions our ideas are welcome.

I have tried this in a regular Android app and all works as expected, so the issue seems to be associated with Flutter Apps only. Perhaps this is what the message: 'Could not find the Android Application module. Only Android Application Modules can be connected to Firebase online projects. Create a new Android Application Module or create/import a different Android Studio project.' means, perhaps currently Firebase does not work with Flutter Apps.

like image 939
Johnos Avatar asked Dec 05 '18 21:12

Johnos


1 Answers

I had the same issue when attempting to connect via the IDE; like many other edges of Flutter/Dart; the firebase assistant UI in Android Studio seems to be one of those cases where the tools have yet to catch up to the tech and delivered the same "Could not find the Android Application module."

This process worked, however: - On firebase console: create/add firebase to cloud project
- On firebase console: add android app icon button
- supplied project package name, nickname, debug SHA1
- On firebase console: downloaded generated google-services.json
- Copied google-services.json to project_dir/android/app - added google-services:4.2.0 dependency to buildscript of project-level build.gradle
- added dependency implementation 'com.google.firebase:firebase-core:16.0.9'(NOT the most recent 17.0.0, so as to avoid dependency collision) to app-level build.gradle
- added "apply plugin: 'com.google.gms.google-services'" at bottom of app-level build.gradle (not sure the position matters?)
- imported firebase_messaging:firebase_messaging.dart
- instantiated and configured a FirebaseMessaging object

This works on a device with telephony, can't say if it does for wifi-only; I notice the versions used in the question are older, but that is to be expected and I don't know if that was Johnos's bane; the lack of an automatic sync is a red flag, however; after I added the above lines via Android Studio in my main flutter project, I saw an option to open the build.gradles in Android studio; I did open a new window for that and built them using the popup "sync" prompts we are all familiar with; I wonder if there was a helpful error swallowed by running this all through the flutterized android studio.

like image 53
anthropic android Avatar answered Nov 08 '22 20:11

anthropic android