Good day all,
I am implementing AWS Amplify DataStore for android following the docs, and basically i get this error when i try to initialize the data store plugin on amplify according to this part of the doc:
Cannot resolve symbol 'AmplifyModelProvider'
You can find code from my gradle files and my application class below.
I am not an android expert, but i believe this is because of a missing dependency or i am doing something wrong during initialization or assignation of the ModelProvider. But i cant find any information on internet about this issue or any possible solution.
Thanks in advance for your help.
Steps to reproduce:
Create new android project
Install Amplify CLI, using npm, npm install -g @aws-amplify/cli
Configure amplify, amplify configure
On new android project root folder, run amplify init, amplify init
On new android project root folder, run amplify add auth, amplify add auth
, adding authentication
Create android application class
Add android application class to AndroidManifest.xml
Try to add data store plugin to amplify on onCreate method of the application class
I already try the following solutions:
Clean project
Rebuild project
Run Make Project
Close and open again Android Studio
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bakeano.htejobs">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MyApplication.java
package com.bakeano.htejobs;
import android.app.Application;
import android.util.Log;
import com.amazonaws.mobile.client.AWSMobileClient;
import com.amazonaws.mobile.client.Callback;
import com.amazonaws.mobile.client.UserStateDetails;
import com.amplifyframework.api.aws.AWSApiPlugin;
import com.amplifyframework.core.Amplify;
import com.amplifyframework.core.model.ModelProvider;
import com.amplifyframework.datastore.AWSDataStorePlugin;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// AWSMobileClient initialization
AWSMobileClient.getInstance().initialize(getApplicationContext(), new Callback<UserStateDetails>() {
@Override
public void onResult(UserStateDetails result) {
try {
ModelProvider modelProvider = AmplifyModelProvider.getInstance(); // Error on this line !!!
Amplify.addPlugin(AWSDataStorePlugin.forModels(modelProvider));
Amplify.addPlugin(new AWSApiPlugin());
Amplify.configure(getApplicationContext());
} catch (Exception e) {
Log.e("bakeanoMessage", "Amplify adding plugins Exception: " + e.getMessage(), e);
}
}
@Override
public void onError(Exception e) {
Log.e("bakeanoMessage", "AWSMobileClient init Exception: " + e.getMessage(), e);
}
});
}
}
Module Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.bakeano.htejobs"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// androidx constraint layout
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
// aws amplify framework core
implementation 'com.amplifyframework:core:0.10.0'
// AWSMobileClient
implementation 'com.amazonaws:aws-android-sdk-mobile-client:2.16.11'
// aws amplify for the drop-in ui
implementation 'com.amazonaws:aws-android-sdk-auth-userpools:2.16.11'
implementation 'com.amazonaws:aws-android-sdk-auth-ui:2.16.11'
// aws amplify api
implementation 'com.amplifyframework:aws-api:0.10.0'
// aws amplify data store
implementation 'com.amplifyframework:aws-datastore:0.10.0'
}
Project Gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
// amplify tools gradle plugin
classpath 'com.amplifyframework:amplify-tools-gradle-plugin:0.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
// applying the amplify tools plugin
apply plugin: 'com.amplifyframework.amplifytools'
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Solution provided by Jameson Williams:
at projects github issue platform - issue #370
AmplifyModelProvider is an autogenerated file that is created by amplify codegen
amplify codegen models
after manual generation you need to import it:
import com.amplifyframework.datastore.generated.model.AmplifyModelProvider;
Thanks !!