capawesome-team / capacitor-firebase

⚡️ Firebase plugins for Capacitor. Supports Android, iOS and the Web.
https://capawesome.io/plugins/firebase/
Apache License 2.0
374 stars 97 forks source link

bug: Android project with facebook login fails lint #117

Open Paso opened 2 years ago

Paso commented 2 years ago

Plugin(s): authentication

Platform(s): android

Current behavior: Linting the android project in CI environment fails when using the facebook provider because of missing dependency.

$ ./gradlew app:lint

> Task :app:lintDebug FAILED
Lint found 2 errors, 42 warnings. First failure:

android/app/src/main/AndroidManifest.xml:124: Error: Class referenced in the manifest, com.facebook.FacebookActivity, was not found in the project or the libraries [MissingClass]
        android:name="com.facebook.FacebookActivity"
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The full lint text report is located at:
  android/app/build/intermediates/lint_intermediate_text_report/debug/lint-results-debug.txt

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:lintDebug'.
> Lint found errors in the project; aborting build.

  Fix the issues identified by lint, or create a baseline to see only new errors:

android { lint { baseline = file("lint-baseline.xml") } }


  For more details, see https://developer.android.com/studio/write/lint#snapshot

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

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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.3.3/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 10s
642 actionable tasks: 1 executed, 641 up-to-date

Expected behavior: ./gradle app:lint should pass

Steps to reproduce: Implement authentication with the facebook provider according to documentation and run ./gradle app:lint

Related code:

facebookLoginVersion = '14.0.0'
<activity android:name="com.facebook.FacebookActivity"

Other information: The project builds and runs in Android Studio.

A workaround I have found is to add the dependency in my top level build.gradle implementation "com.facebook.android:facebook-login:$facebookLoginVersion

My guess is that the linter doesn't like that the dependency is in a subpackage while FacebookActivity is used at the top level (in AndroidManifest.xml). One solution is to change the documentation to say that the dependency should be added manually.

Capacitor doctor:

💊   Capacitor Doctor  💊

Latest Dependencies:

  @capacitor/cli: 3.5.1
  @capacitor/core: 3.5.1
  @capacitor/android: 3.5.1
  @capacitor/ios: 3.5.1

Installed Dependencies:

  @capacitor/cli: 3.4.3
  @capacitor/core: 3.4.3
  @capacitor/android: 3.4.3
  @capacitor/ios: 3.4.3

[error] Xcode is not installed
robingenz commented 2 years ago

Hi @Paso, have you added the following project variable to your variables.gradle file (usually android/build.gradle)?

ext {
+    rgcfaIncludeFacebook = true
}

Does the error only occur during lint or also during build?

Paso commented 2 years ago

Hi @robingenz ,

Yes i do, this is my full variables.gradle:

ext {
    minSdkVersion = 27
    compileSdkVersion = 30
    targetSdkVersion = 30
    androidxActivityVersion = '1.2.0'
    androidxAppCompatVersion = '1.3.0'
    androidxCoordinatorLayoutVersion = '1.1.0'
    androidxCoreVersion =  '1.6.0'
    androidxFragmentVersion = '1.3.0'
    junitVersion = '4.13.2'
    androidxJunitVersion = '1.1.2'
    androidxEspressoCoreVersion = '3.3.0'
    cordovaAndroidVersion =  '7.0.0'
    firebaseMessagingVersion = '23.0.5'
    rgcfaIncludeGoogle = true
    rgcfaIncludeFacebook = true
    facebookLoginVersion = '14.0.0'
}

I get the same error when i run ./gradlew app:build or any of the assemble commands. I find it strange that it works in Android Studio but not in the cli (which is run in the CI environment), but I have long given up on understanding everything Android Studio does 🤷‍♂️.

robingenz commented 2 years ago

Please create a public repository with a minimal, reproducible example and GitHub Actions, so that i can understand the problem.

Paso commented 2 years ago

A minimal reproduction: https://github.com/Paso/fb-auth-repro

git clone https://github.com/Paso/fb-auth-repro
cd fb-auth-repro
npm i
npx cap sync
cd android
./gradlew app:lint
robingenz commented 2 years ago

Thank you, i will look at it as soon as possible.

robingenz commented 2 years ago

I tried your repo and was able to reproduce the error. I compared your repo with https://github.com/robingenz/capacitor-firebase-authentication-demo and I noticed that we have the following diff in the android/build.gradle file:

dependencies {
-    classpath 'com.android.tools.build:gradle:7.2.0'
+    classpath 'com.android.tools.build:gradle:4.2.1'
    classpath 'com.google.gms:google-services:4.3.5'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

With classpath 'com.android.tools.build:gradle:4.2.1' linting works without problems.

github-actions[bot] commented 2 years ago

It looks like there hasn't been a reply in 30 days, so I'm closing this issue.

Paso commented 2 years ago

This probably needs to be fixed at some time.

My suggestion is to update the docs to say that you should manually add the facebook-login dependency. I have manually added it in my project and that makes it work for me.

Downgrading gradle doesn't work for me as I use a newer version of Java that the old gradle doesn't support.

robingenz commented 2 years ago

I will look at it again.

robingenz commented 2 years ago

Unfortunately I could not find out anything more. Waiting for https://github.com/gradle/gradle/issues/21462

robingenz commented 2 years ago

I have unfortunately not received a tip either in the Gradle issue or in this discussion and have no more idea myself.

Since it is only a lint error and the project can be built normally, I will ignore the lint error in my projects with a baseline for now (see Creating a Baseline, example commit).

I will also add a note to the documentation.

Edit: Note added: https://github.com/capawesome-team/capacitor-firebase/commit/c9a5daada7d19f4631688d9ac585937a13bdfff5

mcfarljw commented 1 year ago

I was only able to get the linting errors to resolve after also adding the implementation directly in the build.gradle file as well.

variables.gradle

ext {
  facebookLoginVersion = "15.2.0"
}

build.grade

dependencies {
  implementation "com.facebook.android:facebook-login:$facebookLoginVersion"
}
robingenz commented 1 year ago

I was only able to get the linting errors to resolve after also adding the implementation directly in the build.gradle file as well.

variables.gradle

ext {
  facebookLoginVersion = "15.2.0"
}

build.grade

dependencies {
  implementation "com.facebook.android:facebook-login:$facebookLoginVersion"
}

I do not recommand this solutions since you now have to check the version manually with each update of @capacitor-firebase/authentication and update it if necessary. I recommend ignoring the lint error with a baseline.