Rakesh
Rakesh

Reputation: 199

Failed to find code-generated model provider - AWS Amplify

I'm getting the below error:

Failed to find a code-generated model provider.

AWS amplify code which throwing this error:

Amplify.addPlugin(new AWSApiPlugin());
Amplify.addPlugin(new AWSDataStorePlugin());
Amplify.configure(context);

I am following the below tutorials:

https://docs.amplify.aws/start/getting-started/generate-model/q/integration/android https://docs.amplify.aws/cli/graphql-transformer/overview

I have tried generating models and models get generated successfully but still while running the app I am getting above exception.

Upvotes: 0

Views: 1481

Answers (2)

live-love
live-love

Reputation: 52366

Your datasource needs to be updated:

Try running modelGen, then amplifyPush tasks:

Category Resource name Operation Provider plugin
Api amplifyDatasource Update awscloudformation

enter image description here

Upvotes: 0

Jameson
Jameson

Reputation: 6659

When you generate models, you should expect to find various code-generated files in your application project. One of them will be app/src/main/java/com/amplifyframework/datastore/generated/model/AmplifyModelProvider.java.

When you build your app, Android Studio will compile that java file into a class file, and include it into your binary.

At runtime, on the phone, the AWSDataStorePlugin() constructor will attempt to find that same AmplifyModelProvider by means of reflection.

I would verify that:

  1. You do actually have the code-generated AmplifyModelProvider;
  2. It is being built successfully;
  3. It is not being stripped out by ProGuard/R8 minification.

If you're still not able to get it working, just use the one-argument version of the AWSDataStorePlugin(...) constructor, instead. That version allows you to explicitly specify the model provider, and does not use runtime reflection.

Amplify.addPlugin(AWSDataStorePlugin(AmplifyModelProvider.getInstance()))

Upvotes: 1

Related Questions