Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix android build #106

Merged
merged 4 commits into from
Dec 3, 2024
Merged

Fix android build #106

merged 4 commits into from
Dec 3, 2024

Conversation

cp-sneha-s
Copy link
Collaborator

@cp-sneha-s cp-sneha-s commented Dec 3, 2024

Purpose

Summary of Changes

Test steps

Conformity

  • Followed git guidelines for creating commit messages and Pull Request guidelines.
  • Self-approved the PR - reviewed the PR as a reviewer and gave it self-approval if everything is ok. If not, made the required changes.
  • Ensured that the PR satisfies all specified requirements in the ticket, including bug fixes and new features.
  • Provided test steps, including steps to reproduce the issue or test the new functionality, ensuring other team members can verify the changes.
  • Added/Updated proper code comments to make it easy-to-understand for other developers.
  • Reused code (if the same code was written twice, made it common and reused it at both places).
  • Removed unused or commented code if not required.
  • Ensured proper Dart naming conventions were used for variables, classes, and methods.
  • Localized user-facing strings.
  • Included screenshots/videos of behavior changes: Provided visual evidence of any changes to UI or behavior for easier review and understanding in the PR description.
  • Implemented proper error handling: Ensured that the code anticipated and handled potential errors and edge cases gracefully.
  • Avoided introducing technical debt: If the PR introduces technical debt, created and linked appropriate tickets for future resolution.
  • Included relevant unit tests: Wrote unit tests that focused on testing behavior and functionality, rather than merely covering lines of code.
  • Ensured code was performant and scalable: Verified that the changes did not introduce performance issues or bottlenecks and could scale as needed.
  • Ensured comments were up-to-date and relevant to the code to describe complex logic and to add understanding for other developers.
  • Marked the PR as ready before submitting it for review.

Visual Evidence (Video, Images or Gif)

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced error handling in the sign-in process for Google and Apple sign-ins, providing clearer feedback on specific error conditions.
  • Bug Fixes

    • Improved error management for sign-in exceptions, allowing for more precise responses and better user experience.
  • Chores

    • Updated Gradle and plugin versions for improved build performance and compatibility.
    • Streamlined Android build workflow to allow triggering on any branch push.
    • Removed unnecessary local property handling in the Android configuration.
  • Documentation

    • Updated AndroidManifest files to reflect changes in package declarations and permissions.

Copy link

coderabbitai bot commented Dec 3, 2024

Warning

Rate limit exceeded

@cp-sneha-s has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 27 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b27a58c and 9f927b6.

Walkthrough

The changes in this pull request involve modifications to the Android build configuration and workflow files. The .github/workflows/android_build.yml file has been updated to allow workflow triggers on any branch and includes jobs for building APK and AAB files. The build.gradle file has been streamlined by removing unnecessary plugins and local properties, while the AndroidManifest.xml files have had their package attributes removed. Additionally, the Gradle wrapper and plugin versions have been updated, and error handling in the SignInBloc class has been improved.

Changes

File Path Change Summary
.github/workflows/android_build.yml Removed branch trigger for push event, allowing workflow on any branch; defined jobs for android_build_apk and android_build_aab with steps for building and uploading artifacts.
android/app/build.gradle Removed Google services and Firebase Crashlytics plugins; updated versioning references; increased minSdkVersion from 21 to 34; streamlined configuration by removing local properties.
android/app/src/debug/AndroidManifest.xml Removed package attribute from <manifest> tag; retained INTERNET permission.
android/app/src/main/AndroidManifest.xml Removed package attribute from <manifest> tag; adjusted indentation of <application> tag.
android/app/src/main/kotlin/com/canopas/projectunity/MainActivity.kt Deleted MainActivity class, which served as the entry point for the Flutter application.
android/app/src/main/kotlin/com/canopas/unity/MainActivity.kt Deleted MainActivity class, indicating no designated main activity for Flutter integration.
android/app/src/profile/AndroidManifest.xml Removed package attribute from <manifest> tag; retained INTERNET permission.
android/gradle/wrapper/gradle-wrapper.properties Updated distributionUrl from Gradle 7.3 to 7.6.3.
android/settings.gradle Updated plugin versions for com.android.application from 7.0.4 to 7.3.0 and org.jetbrains.kotlin.android from 1.8.21 to 1.7.10.
lib/ui/sign_in/bloc/sign_in_view_bloc.dart Improved error handling in _googleSignIn and _appleSignIn methods, allowing for more specific exception management.

Possibly related PRs

  • Fix pipeline #103: The changes in this PR also modify the .github/workflows/android_build.yml file, specifically updating action versions, which is closely related to the main PR's changes that enhance the workflow's flexibility and maintainability.
  • Minor fixes #104: This PR adds a distribution parameter in the setup-java action within the .github/workflows/android_build.yml file, which is relevant to the main PR's modifications to the same workflow file.

🐇 In the garden, we hop and play,
With builds that run in a brand new way.
Branches open wide, no more to confine,
APKs and AABs, all aligned!
Flutter’s magic, swift and bright,
Let’s celebrate our code tonight! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (4)
android/app/build.gradle (2)

31-32: Use consistent version property references

For consistency with other Flutter properties, use the same property access style:

-versionCode = flutter.versionCode
-versionName = flutter.versionName
+versionCode flutter.versionCode
+versionName flutter.versionName

19-19: Use consistent Java version reference

For consistency with compileOptions:

-jvmTarget = JavaVersion.VERSION_1_8
+jvmTarget = '1.8'
lib/ui/sign_in/bloc/sign_in_view_bloc.dart (2)

Line range hint 67-77: Enhance Apple sign-in error handling and flow.

While the current implementation is good, consider these improvements:

  1. Handle more specific FirebaseAuthException codes
  2. Move the null check earlier in the flow
  3. Use more specific error messages

Consider this improved implementation:

-    } catch (e, stack) {
-      if (e is FirebaseAuthException && e.code == 'canceled') {
+    } on FirebaseAuthException catch (e, stack) {
+      if (e.code == 'canceled' || e.code == 'popup_closed_by_user') {
         emit(state.copyWith(appleSignInLoading: false));
         return;
       }
+      String errorMessage = switch (e.code) {
+        'invalid-credential' => 'Invalid credentials provided',
+        'user-disabled' => 'This account has been disabled',
+        _ => somethingWentWrongError
+      };
       FirebaseCrashlytics.instance
           .recordError(e, stack, reason: 'Apple Sign In Error');
       emit(state.copyWith(
-          appleSignInLoading: false, error: somethingWentWrongError));
+          appleSignInLoading: false, error: errorMessage));
+    } catch (e, stack) {
+      FirebaseCrashlytics.instance
+          .recordError(e, stack, reason: 'Apple Sign In Error');
+      emit(state.copyWith(
+          appleSignInLoading: false, error: somethingWentWrongError));
     }

Line range hint 1-85: Consider architectural improvements for better maintainability.

The current implementation could benefit from:

  1. Centralizing error handling logic to ensure consistency between sign-in methods
  2. Extracting common sign-in flow logic to reduce code duplication

Consider creating:

  1. A common error handler:
class AuthErrorHandler {
  static SignInState handleError(
    dynamic error,
    StackTrace stack,
    String source,
    bool loading,
  ) {
    if (error is FirebaseAuthException) {
      if (error.code == 'canceled' || error.code == 'popup_closed_by_user') {
        return SignInState(loading: false);
      }
      // Handle other specific cases
    }
    FirebaseCrashlytics.instance.recordError(error, stack, reason: '$source Error');
    return SignInState(loading: false, error: somethingWentWrongError);
  }
}
  1. A base sign-in method:
Future<SignInState> _handleSignIn(
  Future<firebase_auth.User?> Function() signInMethod,
  Future<Account?> Function(firebase_auth.User) getUserMethod,
  bool loading,
) async {
  try {
    final authUser = await signInMethod();
    if (authUser == null) return SignInState(loading: false);
    
    final user = await getUserMethod(authUser);
    if (user == null) {
      return SignInState(
        loading: false,
        error: 'User not found',
        firebaseAuthUser: authUser,
      );
    }
    
    await _userStateNotifier.setUser(user);
    return SignInState(loading: false, signInSuccess: true);
  } catch (e, stack) {
    return AuthErrorHandler.handleError(e, stack, 'Sign In', loading);
  }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 929667a and 30f5633.

📒 Files selected for processing (10)
  • .github/workflows/android_build.yml (0 hunks)
  • android/app/build.gradle (2 hunks)
  • android/app/src/debug/AndroidManifest.xml (1 hunks)
  • android/app/src/main/AndroidManifest.xml (1 hunks)
  • android/app/src/main/kotlin/com/canopas/projectunity/MainActivity.kt (0 hunks)
  • android/app/src/main/kotlin/com/canopas/unity/MainActivity.kt (0 hunks)
  • android/app/src/profile/AndroidManifest.xml (1 hunks)
  • android/gradle/wrapper/gradle-wrapper.properties (1 hunks)
  • android/settings.gradle (1 hunks)
  • lib/ui/sign_in/bloc/sign_in_view_bloc.dart (1 hunks)
💤 Files with no reviewable changes (3)
  • android/app/src/main/kotlin/com/canopas/projectunity/MainActivity.kt
  • android/app/src/main/kotlin/com/canopas/unity/MainActivity.kt
  • .github/workflows/android_build.yml
✅ Files skipped from review due to trivial changes (3)
  • android/app/src/profile/AndroidManifest.xml
  • android/app/src/debug/AndroidManifest.xml
  • android/gradle/wrapper/gradle-wrapper.properties
🔇 Additional comments (2)
android/app/src/main/AndroidManifest.xml (1)

1-1: Verify package name configuration

The package attribute has been removed from the manifest. While this is supported when using the Android Gradle Plugin namespace feature, ensure that:

  1. All resource references in code are updated
  2. The namespace in build.gradle matches the previous package name to maintain compatibility

Also applies to: 3-3

✅ Verification successful

The previous commands didn't yield results, so let's try a broader search to:

  1. Find namespace configuration in build.gradle
  2. Look for R imports across different file types
  3. Check package declarations in source files
  4. Examine MainActivity implementation

This will help us verify the package name configuration and its impact on resource references.


Package configuration is properly set up

The package name is correctly configured in the Android project:

  • The namespace is defined in build.gradle as com.example.canopas_unity
  • The applicationId is set to com.canopas.projectunity
  • MainActivity is properly declared in the correct package structure

The removal of the package attribute from AndroidManifest.xml is safe as the Android Gradle Plugin's namespace feature is being used correctly. No resource reference issues were found in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential resource reference issues
rg "R\." --type kotlin --type java

# Check for activity class references
rg "\.MainActivity" --type kotlin --type java

Length of output: 84


Script:

#!/bin/bash
# Check build.gradle files for namespace configuration
fd "build.gradle" --type f --exec cat {}

# Check for any R imports or references in all text files
rg -t txt -t java -t kotlin -t xml "import.*R" -A 2

# Look for package declarations in Java/Kotlin files
rg "package\s+[\w\.]+" --type kotlin --type java

# Check MainActivity declarations
fd "MainActivity" --type f --exec cat {}

Length of output: 3463

android/app/build.gradle (1)

Line range hint 33-37: Verify APK naming convention

The APK naming uses versionName and versionCode variables. Ensure these are properly populated from flutter.versionName and flutter.versionCode:

✅ Verification successful

APK naming convention is correctly configured

The version properties are properly set up:

  • Flutter version is defined in pubspec.yaml as 1.0.2+2
  • The build.gradle correctly references flutter.versionName and flutter.versionCode
  • These values are properly used in the APK naming convention
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if version properties are defined in Flutter
grep -r "version:" $(find . -name "pubspec.yaml")

Length of output: 79


Script:

#!/bin/bash
# Check how versionName and versionCode are defined in build.gradle files
rg "versionName|versionCode" -A 2 --type gradle

Length of output: 517

android/settings.gradle Show resolved Hide resolved
android {
compileSdkVersion 34//flutter.compileSdkVersion
namespace = "com.example.canopas_unity"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Update namespace to use production domain

The namespace is using an example domain which should not be used in production:

-namespace = "com.example.canopas_unity"
+namespace = "com.canopas.projectunity"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
namespace = "com.example.canopas_unity"
namespace = "com.canopas.projectunity"

android/app/build.gradle Show resolved Hide resolved
Comment on lines 8 to +11
compileSdkVersion 34//flutter.compileSdkVersion
namespace = "com.example.canopas_unity"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix inconsistent SDK version configuration

The compileSdkVersion is both hardcoded and referenced from flutter:

-compileSdkVersion 34//flutter.compileSdkVersion
-compileSdk = flutter.compileSdkVersion
+compileSdkVersion flutter.compileSdkVersion

Committable suggestion skipped: line range outside the PR's diff.

lib/ui/sign_in/bloc/sign_in_view_bloc.dart Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
android/app/build.gradle (2)

Line range hint 39-49: Security: Remove debug signing configuration from production

The fallback signing configuration uses development keys which should not be included in the production build configuration. Consider moving this to a separate debug configuration file.


Line range hint 66-71: Debug builds should not use minification

Enabling minification for debug builds can make debugging more difficult. Consider disabling minification for debug builds:

debug {
-    minifyEnabled true
+    minifyEnabled false
    debuggable true
    signingConfig signingConfigs.release
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 30f5633 and b27a58c.

📒 Files selected for processing (2)
  • .github/workflows/android_build.yml (1 hunks)
  • android/app/build.gradle (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/android_build.yml
🔇 Additional comments (6)
android/app/build.gradle (6)

8-8: Fix inconsistent SDK version configuration

The compileSdkVersion is both hardcoded and referenced from flutter.


9-9: Update namespace to use production domain

The namespace is using an example domain which should not be used in production.


19-19: LGTM: Improved JVM target configuration

Good improvement using JavaVersion constant instead of string literal for better type safety.


29-30: Critical: Extremely high minSdkVersion

Setting minSdkVersion to 34 (Android 14) will prevent the app from running on most Android devices.


30-32: LGTM: Proper version configuration

Good use of Flutter version references for consistent version management.


82-82: LGTM: Proper file ending

Good practice to end the file with a newline.

@cp-sneha-s cp-sneha-s merged commit c2bf90c into main Dec 3, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant