Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. In your implementation include the version 2 dependency of client core

Code Block
languagegroovy
implementation('org.smartregister:opensrp-client-core:2.0.6-SNAPSHOT@aar') {
    transitive = true
    ... 

2. In your project’s build.gradle file, add the following code block after the buildConfigField entries in the defaultConfig block

Code Block
languagegroovy
 if (project.rootProject.file("local.properties").exists()) {  
       
     Properties properties = new Properties()
            properties.load(project.rootProject.file("local.properties").newDataInputStream())

            if (properties != null && properties.containsKey("oauth.client.id")) {

                buildConfigField "String", "OAUTH_CLIENT_ID", properties["oauth.client.id"]

            } else {
                project.logger.error("oauth.client.id variable is not set in your local.properties")
                buildConfigField "String", "OAUTH_CLIENT_ID", "\"sample_client_id\""
            }


            if (properties != null && properties.containsKey("oauth.client.secret")) {

                buildConfigField "String", "OAUTH_CLIENT_SECRET", properties["oauth.client.secret"]

            } else {
                project.logger.error("oauth.client.secret variable is not set in your local.properties")
                buildConfigField "String", "OAUTH_CLIENT_SECRET", "\"sample_client_secret\""
            }        
    }

...

4. In your application, from the class that inherits DrishtiApplication.java class, remove the following code block. This should now be delegated to super.

Code Block
languagejava
public String getPassword() {
    if (password == null) {
        String username = getContext().userService().getAllSharedPreferences().fetchRegisteredANM();
        password = getContext().userService().getGroupId(username);
    }
    return password;
}

5. In your application's Configuration class (Class that extends core’s SyncConfiguration), you need to override the following methods

Code Block
languagegroovy
    @Override 
    public String getOauthClientId() { 
           return BuildConfig.OAUTH_CLIENT_ID;    
    }
    
    @Override    
    public String getOauthClientSecret() {        
           return BuildConfig.OAUTH_CLIENT_SECRET;    
    }
    
    @Override  
    public Class<? extends BaseLoginActivity> getAuthenticationActivity() {    
            return LoginActivity.class;    
    }

6. In your application(or sample app) , under the path src/main/res/xml/ create a file like this and name it authenticator.xml.

Remember to change the org.smartregister.xxx with the actual package signature of your app

Code Block
languagexml
<?xml version="1.0" encoding="

...

UTF-8"?>

...


<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"

...

 
  android:accountType="org.smartregister.xxx"

...

 
  android:icon="@mipmap/ic_launcher"

...

 
  android:label="@string/app_name"

...

 
  android:smallIcon="@mipmap/ic_launcher" />

Other updates

Core version 2.0 also includes FHIR dependencies which have functionality that requires a minimum Android O (API 26). To get around this you need to exclude these features from being included at compile time. The steps for this workaround are :

  1. In your project's root build.gradle file, add the following dependency to the build script dependencies

Code Block
languagegroovy
buildscript {

    repositories {
            ...
            maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
        }    
        
    dependencies {
            ... 
            classpath 'org.smartregister:gradle-jarjar-plugin:1.0.0-SNAPSHOT'
       }
       

...

3. You then need to exclude the ibm fhir dependencies and include those compiled via jarjar. All the dependency updates for your app module’s build.gradle should now be the following.

Code Block
languagegroovy
implementation('org.smartregister:opensrp-client-core:2.0.6-SNAPHOT@aar') {
    transitive = true
    ...
    exclude group: 'com.ibm.fhir', module: 'fhir-model'
}

jarJar 'com.ibm.fhir:fhir-model:4.2.3'

implementation fileTree(dir: "./build/libs", include: ['*.jar'])

...

If you already have an annotationsProcessorOptions block, set the includeCompileClasspath field totrue

Code Block
languagegroovy
defaultConfig{
  ...
  javaCompileOptions {
      annotationProcessorOptions {
          ...
          includeCompileClasspath = true
      }

5. Finally on the same app module build.gradle script, add the following lines to exclude duplicate files within the packagingOptions block

Code Block
languagegroovy
 packagingOptions {
       ...
       exclude 'META-INF/LICENSE.md'
       exclude 'META-INF/NOTICE.md'
  }

...

c) Most methods in the UserService class are now dependent on the current logged in user, e.g.

Code Block
languagejava
String username = getContext().userService().getAllSharedPreferences().fetchRegisteredANM();
context.userService().forceRemoteLogin(username);

d) SmartRegisterQueryBuilder method queryBuilder.SelectInitiateMainTable( is now queryBuilder.selectInitiateMainTable(

Code Block
languagejava
SmartRegisterQueryBuilder queryBuilder = new SmartRegisterQueryBuilder();
queryBuilder.selectInitiateMainTable(tableName, columns)

...

update the null parameter for your metadata to an empty string

Code Block
languagejava
startFormActivity('my_form_name' , null , null) -> startFormActivity('my_form_name' , null , "");

...