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

MissingPluginException when following trip planner tutorial #2583

Closed
Jordan-Nelson opened this issue Jan 18, 2023 · 10 comments
Closed

MissingPluginException when following trip planner tutorial #2583

Jordan-Nelson opened this issue Jan 18, 2023 · 10 comments
Assignees
Labels
Android Issues specific to the Android Platform pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days. pending-triage This issue is in the backlog of issues to triage to-be-reproduced Issues that have not been reproduced yet, but have reproduction steps provided

Comments

@Jordan-Nelson
Copy link
Contributor

Issue created from comment on #2551.


Comment

Hi Jordan - I actually have a very similar issue. I'm following an AWS tutorial, which up until today, after I updated my Android SDK, I haven't had too much of an issue.

Here's my stuff - I'm a beginner at this so I might have messed something up, but it had been working fine until today.

Launching lib\main.dart on SM S901U in debug mode...
Running Gradle task 'assembleDebug'...
√  Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...
Debug service listening on ws://127.0.0.1:57740/L4njAY89pIo=/ws
Syncing files to device SM S901U...
I/ionsapplication( 7893): Compiler allocated 6075KB to compile void android.view.ViewRootImpl.performTraversals()
I/flutter ( 7893): Amplify plugin was not added
E/flutter ( 7893): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: AmplifyException(message: Amplify plugin AmplifyAuthCognitoMethodChannel was not added successfully., recoverySuggestion: We currently don't have a recovery suggestion for this exception., underlyingException: AmplifyException(message: MissingPluginException(No implementation found for method addPlugin on channel com.amazonaws.amplify/auth_cognito), recoverySuggestion: null, underlyingException: null))
E/flutter ( 7893): #0      MethodChannelAmplify.addPlugin (package:amplify_flutter/src/method_channel_amplify.dart:66:7)
E/flutter ( 7893): <asynchronous suspension>
E/flutter ( 7893): #1      Future.wait.<anonymous closure> (dart:async/future.dart:522:21)
E/flutter ( 7893): <asynchronous suspension>
E/flutter ( 7893): #2      _configureAmplify (package:reaqtionsapplication/main.dart:28:3)
E/flutter ( 7893): <asynchronous suspension>
E/flutter ( 7893): #3      main (package:reaqtionsapplication/main.dart:12:5)
E/flutter ( 7893): <asynchronous suspension>
E/flutter ( 7893): 

Here's my main dart file

import 'package:reaqtionsapplication/reaqtions_app.dart';
import 'package:flutter/material.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'amplifyconfiguration.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  bool isAmplifySuccessfullyConfigured = false;
  try {
    await _configureAmplify();
    isAmplifySuccessfullyConfigured = true;
  } on AmplifyAlreadyConfiguredException {
    debugPrint('Amplify configuration failed.');
  }

  runApp(
    ProviderScope(
      child: ReAQtionsApp(
        isAmplifySuccessfullyConfigured: isAmplifySuccessfullyConfigured,
      ),
    ),
  );
}

Future<void> _configureAmplify() async {
  await Amplify.addPlugins([
    AmplifyAuthCognito(),
  ]);
  await Amplify.configure(amplifyconfig);
}

And here is the app file

import 'package:reaqtionsapplication/features/airquality/ui/aqi_list/aqi_list_page.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:amplify_authenticator/amplify_authenticator.dart';
import 'package:reaqtionsapplication/common/navigation/router/routes.dart';
import 'package:reaqtionsapplication/common/utils/colors.dart' as constants;

class ReAQtionsApp extends StatelessWidget {
  const ReAQtionsApp({
    required this.isAmplifySuccessfullyConfigured,
    Key? key,
  }) : super(key: key);

  final bool isAmplifySuccessfullyConfigured;

  @override
  Widget build(BuildContext context) {
    final router = GoRouter(
      routes: [
        GoRoute(
          path: '/',
          name: AppRoute.home.name,
          builder: (context, state) => isAmplifySuccessfullyConfigured
              ? const AQIListPage()
              : const Scaffold(
            body: Center(
              child: Text(
                'Tried to reconfigure Amplify; '
                    'this can occur when your app restarts on Android.',
              ),
            ),
          ),
        ),
      ],
      errorBuilder: (context, state) => Scaffold(
        body: Center(
          child: Text(state.error.toString()),
        ),
      ),
    );

    return Authenticator(
      child: MaterialApp.router(
        routeInformationParser: router.routeInformationParser,
        routeInformationProvider: router.routeInformationProvider,
        routerDelegate: router.routerDelegate,
        builder: Authenticator.builder(),
        theme: ThemeData(
          primarySwatch: constants.primaryColor,
          backgroundColor: const Color(0xff82CFEA),
        ),
      ),
    );
  }
}

Finally, here are the dependencies:

version: 1.0.0+1

environment:
  sdk: ">=2.18.4 <3.0.0"

dependencies:
  amplify_api: ^0.6.0
  amplify_auth_cognito: ^0.6.0
  amplify_authenticator: ^0.2.2
  amplify_datastore: ^0.6.0
  amplify_flutter: ^0.6.0
  amplify_storage_s3: ^0.6.0
  cached_network_image: ^3.2.1
  cupertino_icons: ^1.0.2
  flutter:
    sdk: flutter
  flutter_hooks: ^0.18.5+1
  flutter_riverpod: ^1.0.4
  go_router: ^4.1.0
  hooks_riverpod: ^1.0.4
  image_picker: ^0.8.5+3
  intl: ^0.17.0

dev_dependencies:
  flutter_lints: ^2.0.1
  flutter_test:
    sdk: flutter



flutter:
  uses-material-design: true
  plugin:
    platforms:
      android:
        package: io.github.edufolly.flutterbluetoothserial
        pluginClass: FlutterBluetoothSerialPlugin

Thanks so much

Originally posted by @nabram in #2551 (comment)

@ragingsquirrel3 ragingsquirrel3 added pending-triage This issue is in the backlog of issues to triage Android Issues specific to the Android Platform labels Jan 18, 2023
@ragingsquirrel3
Copy link
Contributor

@nabram sorry you are having this issue with the tutorial. I could not reproduce this exception but I wanted to ask some followup questions to ensure I'm not missing something relevant:

  • You mentioned you updated Android SDK. Could you please attach output of flutter doctor? That will indicate which version you are having this issue with.
  • Could you please add source for 'package:reaqtionsapplication/features/airquality/ui/aqi_list/aqi_list_page.dart'; as not sure if this might have something relevant (doesn't seem likely).
  • Could you attach the contents of your amplifyconfiguration.dart file with any API keys, user Pool IDs, resource identifiers etc... anonymized?
  • At what point in tutorial did you have this issue?
  • Is the source for your app available anywhere that we could use to repro? If not is ok, will continue trying to repro in same way.

@ragingsquirrel3 ragingsquirrel3 added pending-response Issue is pending response from the issue requestor to-be-reproduced Issues that have not been reproduced yet, but have reproduction steps provided labels Jan 18, 2023
@nabram
Copy link

nabram commented Jan 20, 2023

Hi @ragingsquirrel3 - I just updated my flutter today. I tried running the program and still had issues. I've attached what you're looking for now.

1. Flutter doctor readout

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.3.10, on Microsoft Windows [Version 10.0.22621.1105], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.11.17)
[√] Android Studio (version 2022.1)
[√] VS Code (version 1.74.3)
[√] Connected device (4 available)
[√] HTTP Host Availability

• No issues found!

2. AQI List

import 'package:flutter/material.dart';
import 'package:reaqtionsapplication/common/utils/colors.dart' as constants;

class AQIListPage extends StatelessWidget {
  const AQIListPage({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: const Text(
          'ReAQtions CanAIRy Pollutants',
        ),
        backgroundColor: const Color(constants.primaryColorDark),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {},
        backgroundColor: const Color(constants.primaryColorDark),
        child: const Icon(Icons.add),
      ),
      body: const Center(
        child: Text('Pollutant List'),
      ),
    );
  }
}

3. amplifyconfiguration.dart

const amplifyconfig = ''' {
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify-cli/0.1.0",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "pool id",
                            "Region": "us-east-1"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "pool id",
                        "AppClientId": "app id",
                        "Region": "us-east-1"
                    }
                },
                "Auth": {
                    "Default": {
                        "authenticationFlowType": "USER_SRP_AUTH",
                        "socialProviders": [],
                        "usernameAttributes": [
                            "EMAIL"
                        ],
                        "signupAttributes": [
                            "EMAIL"
                        ],
                        "passwordProtectionSettings": {
                            "passwordPolicyMinLength": 8,
                            "passwordPolicyCharacters": []
                        },
                        "mfaConfiguration": "OFF",
                        "mfaTypes": [
                            "SMS"
                        ],
                        "verificationMechanisms": [
                            "EMAIL"
                        ]
                    }
                }
            }
        }
    }
}''';

4. Module where the issue occurred###

I was at the end of module 2. I was trying to run test the authentication and received the error that the plugins were not added.

5. Source

It's currently not but if there's still issues, I'm happy to upload it to git

@Jordan-Nelson
Copy link
Contributor Author

@nabram Based on the following two lines from the log:

I/flutter ( 7893): Amplify plugin was not added
E/flutter ( 7893): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: AmplifyException(message: Amplify plugin AmplifyAuthCognitoMethodChannel was not added successfully., recoverySuggestion: We currently don't have a recovery suggestion for this exception., underlyingException: AmplifyException(message: MissingPluginException(No implementation found for method addPlugin on channel com.amazonaws.amplify/auth_cognito), recoverySuggestion: null, underlyingException: null))

The exception is being thrown when trying to add the Auth plugin. You can see where that log/exception comes from in Amplify below.

} on Exception catch (e) {
safePrint('Amplify plugin was not added');
throw AmplifyException(
'Amplify plugin ${plugin.runtimeType} was not added successfully.',
recoverySuggestion: AmplifyExceptionMessages.missingRecoverySuggestion,
underlyingException: e.toString(),
);
}

I notice in the code you provided above, you have a try/catch around Amplify.addPlugins(), which prints, "Amplify configuration failed". I don't see that in your log output though. That would indicate that Amplify.addPlugins or Amplify.addPlugin is being called somewhere else in your app. Can you see if you have any calls to any of the following functions outside of the code you have provided?

  • Amplify.addPlugins
  • Amplify.addPlugin
  • Amplify.configure
  • _configureAmplify

@nabram
Copy link

nabram commented Jan 23, 2023

I have the await Amplify.addPlugins function in the main.dart that I provided in the first question. I'll repaste the main.dart

import 'package:reaqtionsapplication/reaqtions_app.dart';
import 'package:flutter/material.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'amplifyconfiguration.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  bool isAmplifySuccessfullyConfigured = false;
  try {
    await _configureAmplify();
    isAmplifySuccessfullyConfigured = true;
  } on AmplifyAlreadyConfiguredException {
    debugPrint('Amplify configuration failed.');
  }

  runApp(
    ProviderScope(
      child: ReAQtionsApp(
        isAmplifySuccessfullyConfigured: isAmplifySuccessfullyConfigured,
      ),
    ),
  );
}

Future<void> _configureAmplify() async {
  await Amplify.addPlugins([ ///<==This is where I'm calling the addPlugins. 
    AmplifyAuthCognito(),
  ]);
  await Amplify.configure(amplifyconfig);
}

Edit: I'd also like to add that I did not have this issue until I updated Android SDK. I don't know if that has anything to do with it.

@ragingsquirrel3 ragingsquirrel3 removed the pending-response Issue is pending response from the issue requestor label Feb 7, 2023
@Jordan-Nelson
Copy link
Contributor Author

Hello @nabram - Can you let us know if you are still facing this issue? I think @ragingsquirrel3 had spent some time trying to reproduce this and was unsuccessful.

@Jordan-Nelson Jordan-Nelson added the pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days. label Apr 20, 2023
@Jordan-Nelson
Copy link
Contributor Author

@nabram - I am going to close this out since I have not heard back. If you are still facing this issue, please let us know.

@emmaezeumeh
Copy link

Hello Jordan,

I am also a beginner working on the trip planner aws amplify tutorial but I am encountering different problems. One at the end of part 1 and the other at the end of part 2 when I run flutter

Here's prroblem 1:
[{
"resource": "~/amplify_trips_planner/android/app/build.gradle",
"owner": "generated_diagnostic_collection_name#2",
"severity": 8,
"message": "unable to resolve class GradleException\n @ line 11, column 15.",
"source": "Gradle",
"startLineNumber": 11,
"startColumn": 15,
"endLineNumber": 11,
"endColumn": 16
}]

build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
namespace "com.example.amplify_trips_planner"
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
    jvmTarget = '1.8'
}

sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.amplify_trips_planner"
    // You can update the following values to match your application needs.
    // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
    minSdkVersion 21
    targetSdkVersion flutter.targetSdkVersion
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    
}

buildTypes {
    release {
        // TODO: Add your own signing config for the release build.
        // Signing with the debug keys for now, so `flutter run --release` works.
        signingConfig signingConfigs.debug
    }
}

}

flutter {
source '../..'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

Problem 2:

The name 'MyApp' isn't a class.
Try correcting the name to match an existing class.

Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
../.pub-cache/hosted/pub.dev/go_router-4.5.1/lib/src/router.dart:38:44: Error: The class 'NavigatorObserver' can't be used as a mixin because it isn't a mixin class nor a mixin.
class GoRouter extends ChangeNotifier with NavigatorObserver {
^
Target kernel_snapshot failed: Exception

FAILURE: Build failed with an exception.

  • Where:
    Script '~/Development/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1201

  • What went wrong:
    Execution failed for task ':app:compileFlutterBuildDebug'.

Process 'command '~/Development/flutter/bin/flutter'' finished with non-zero exit value 1

  • 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.

BUILD FAILED in 7s
Running Gradle task 'assembleDebug'... 7.8s
Exception: Gradle task assembleDebug failed with exit code 1

my public.yaml

name: amplify_trips_planner
description: A new Flutter project.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
sdk: '>=2.18.0 <3.0.0'

dependencies:
amplify_api: ^0.6.0
amplify_auth_cognito: ^0.6.0
amplify_authenticator: ^0.2.2
amplify_datastore: ^0.6.0
amplify_flutter: ^0.6.0
amplify_storage_s3: ^0.6.0
cached_network_image: ^3.2.1
cupertino_icons: ^1.0.2
flutter:
sdk: flutter
flutter_hooks: ^0.18.5+1
flutter_riverpod: ^1.0.4
go_router: ^4.1.0
hooks_riverpod: ^1.0.4
image_picker: ^0.8.5+3
intl: ^0.18.0

dev_dependencies:
flutter_lints: ^2.0.1
flutter_test:
sdk: flutter

flutter:
uses-material-design: true
assets:
- images/amplify.png

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.4.1 22F82 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✗] Xcode - develop for iOS and macOS
✗ Xcode installation is incomplete; a full installation is necessary for iOS and macOS development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin
usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.80.2)
[✓] Connected device (3 available)
[✓] Network resources

! Doctor found issues in 1 category.

amplifyconfiguration.dart

const amplifyconfig = '''{
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "us-east-2:271ade85-d325-4847-8bea-be748e2bc1c1",
"Region": "us-east-2"
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "us-east-2_ELEHpWeNy",
"AppClientId": "2f9185vktrrseg88ckriikd94u",
"Region": "us-east-2"
}
},
"Auth": {
"Default": {
"authenticationFlowType": "USER_SRP_AUTH",
"socialProviders": [],
"usernameAttributes": [
"EMAIL"
],
"signupAttributes": [
"EMAIL"
],
"passwordProtectionSettings": {
"passwordPolicyMinLength": 8,
"passwordPolicyCharacters": []
},
"mfaConfiguration": "OFF",
"mfaTypes": [
"SMS"
],
"verificationMechanisms": [
"EMAIL"
]
}
}
}
}
}
}''';

main.dart

import 'package:amplify_trips_planner/trips_planner_app.dart';
import 'package:flutter/material.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'amplifyconfiguration.dart';

Future main() async {
WidgetsFlutterBinding.ensureInitialized();
bool isAmplifySuccessfullyConfigured = false;
try {
await _configureAmplify();
isAmplifySuccessfullyConfigured = true;
} on AmplifyAlreadyConfiguredException {
debugPrint('Amplify configuration failed.');
}

runApp(
ProviderScope(
child: TripsPlannerApp(
isAmplifySuccessfullyConfigured: isAmplifySuccessfullyConfigured,
),
),
);
}

Future _configureAmplify() async {
await Amplify.addPlugins([
AmplifyAuthCognito(),
]);
await Amplify.configure(amplifyconfig);
}

Please how can I resolve these?

@Jordan-Nelson
Copy link
Contributor Author

@ieakpoveta - Please up grade to the latest version of amplify flutter. If you are still facing issues with the tutorial, feel free to open an issue and fill out the details in the issue template.

@jhansen8
Copy link

@ieakpoveta I had the same issue, try updating all amplify_* dependencies to ^1.0.0 and then go_router to ^6.5.5.

This resolved my issue and the tutorial should be updated as well. @Jordan-Nelson

@Jordan-Nelson
Copy link
Contributor Author

Thanks. We are working on updating the tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Issues specific to the Android Platform pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days. pending-triage This issue is in the backlog of issues to triage to-be-reproduced Issues that have not been reproduced yet, but have reproduction steps provided
Projects
None yet
Development

No branches or pull requests

5 participants