Amplitude.initialize is not available on android

After upgrading to ExpoKit SDK 33 and building an APK and uploading it to internal test on Google Play, I get the error

Uncaught Error: Error: The method or property Amplitude.initialize is not available on android, are you sure you've linked all the native dependencies properly?

I’m using the new imports: import * as Amplitude from 'expo-analytics-amplitude';.

Someone else had the problem here as well Amplitude Error for Android.

I’m not getting this error when debugging on a physical device from Android Studio. If I remove the call to initialize, I get the same error on .logEvent method, so I guess it’s something with the Amplitude library entirely.

This is my app build.gradle:

buildscript {
  repositories {
    google()
    maven { url 'https://maven.fabric.io/public' }
    maven { url 'https://plugins.gradle.org/m2/' }
  }

  dependencies {
    classpath 'io.fabric.tools:gradle:1.+'
    classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.1, 0.99.99]'
  }
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
  maven { url 'https://maven.fabric.io/public' }
}

android {
  compileSdkVersion 28
  buildToolsVersion '27.0.3'

  defaultConfig {
    applicationId 'com.plantjammer.plantjammer'
    targetSdkVersion 28
    versionCode 375
    versionName '2.59.45'
    ndk {
      abiFilters 'armeabi-v7a', 'x86', 'arm64-v8a', 'x86-64'
    }
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    // Deprecated. Used by net.openid:appauth
    manifestPlaceholders = [
            'appAuthRedirectScheme': 'host.exp.exponent'
    ]
    minSdkVersion 21
  }
  dexOptions {
    javaMaxHeapSize System.getenv("DISABLE_DEX_MAX_HEAP") ? null : "8g"
  }
  buildTypes {
    debug {
      debuggable true
      ext.enableCrashlytics = false
    }
    release {
      minifyEnabled true
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      zipAlignEnabled true
    }
  }
  signingConfigs {
    debug {
      storeFile file('../debug.keystore')
    }
  }
  lintOptions {
    abortOnError false
  }
  packagingOptions {
    pickFirst "**"
  }
  configurations.all {
    resolutionStrategy.force 'com.android.support:design:28.0.0'
  }
  compileOptions {
    sourceCompatibility 1.8
    targetCompatibility 1.8
  }
}

// Don't use modern jsc-android since it still has some critical bugs that
// crash applications when the string for the JS bundle is loaded and when
// locale-specific date functions are called.
// configurations.all {
//   resolutionStrategy {
//     force 'org.webkit:android-jsc:r216113'
//   }
// }


apply from: 'expo.gradle'

apply from: "../../node_modules/react-native-unimodules/gradle.groovy"

dependencies {
  api project(':react-native-iap')
  api project(':react-native-onesignal')
  api fileTree(dir: 'libs', include: ['*.jar'])

  api 'com.android.support:multidex:1.0.1'

  // Our dependencies
  api 'com.android.support:appcompat-v7:28.0.0'

  // Our dependencies from ExpoView
  // DON'T ADD ANYTHING HERE THAT ISN'T IN EXPOVIEW. ONLY COPY THINGS FROM EXPOVIEW TO HERE.
  api 'com.android.support:appcompat-v7:28.0.0'
  api 'com.facebook.android:facebook-android-sdk:4.34.0'
  api('com.facebook.android:audience-network-sdk:4.99.0') {
    exclude module: 'play-services-ads'
  }
  compileOnly 'org.glassfish:javax.annotation:3.1.1'
  api 'com.jakewharton:butterknife:8.4.0'
  api 'de.greenrobot:eventbus:2.4.0'
  api 'com.amplitude:android-sdk:2.9.2' // Be careful when upgrading! Upgrading might break experience scoping. Check with Jesse. See Analytics.resetAmplitudeDatabaseHelper
  api 'com.squareup.picasso:picasso:2.5.2'
  api 'com.google.android.gms:play-services-gcm:15.0.1'
  api 'com.google.android.gms:play-services-analytics:16.0.1'
  api 'com.google.android.gms:play-services-maps:15.0.1'
  api 'com.google.android.gms:play-services-auth:15.0.1'
  api 'com.google.android.gms:play-services-location:15.0.1'
  api 'com.google.android.gms:play-services-ads:15.0.1'
  annotationProcessor 'com.raizlabs.android:DBFlow-Compiler:2.2.1'
  api "com.raizlabs.android:DBFlow-Core:2.2.1"
  api "com.raizlabs.android:DBFlow:2.2.1"
  api "com.madgag.spongycastle:core:1.53.0.0"
  api "com.madgag.spongycastle:prov:1.53.0.0"
  debugImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
  // debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.4-beta1'
  releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
  api 'com.facebook.device.yearclass:yearclass:1.0.1'
  api 'commons-io:commons-io:1.3.2'
  api 'me.leolin:ShortcutBadger:1.1.4@aar'
  api 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
  api 'com.theartofdev.edmodo:android-image-cropper:2.4.7'
  api 'com.yqritc:android-scalablevideoview:1.0.1'
  api 'commons-codec:commons-codec:1.10'
  api 'com.segment.analytics.android:analytics:4.3.0'
  api 'com.google.zxing:core:3.2.1'
  api 'net.openid:appauth:0.4.1'
  api('com.airbnb.android:lottie:2.5.5')  {
      exclude group: 'com.android.support', module: 'appcompat-v7'
  }
  api 'io.branch.sdk.android:library:2.17.1'
  api('io.nlopez.smartlocation:library:3.2.11') {
    transitive = false
  }
  api 'com.android.support:exifinterface:28.0.0'
  api 'com.squareup.okio:okio:1.9.0'

  // Testing
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
  // We use a modified build of com.android.support.test:runner:1.0.1. Explanation in maven-test/README
  androidTestImplementation 'com.android.support.test:runner:1.0.1'
  androidTestImplementation 'com.android.support:support-annotations:28.0.0'
  androidTestImplementation 'com.google.code.findbugs:jsr305:3.0.0'
  androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
  androidTestImplementation 'com.azimolabs.conditionwatcher:conditionwatcher:0.2'

  testImplementation 'junit:junit:4.12'
  testImplementation 'org.mockito:mockito-core:1.10.19'
  testImplementation 'org.robolectric:robolectric:3.8'
  testImplementation 'com.android.support.test:runner:1.0.2-alpha1'
  testImplementation 'com.android.support.test:rules:1.0.2-alpha1'

  
  api('host.exp.exponent:expoview:33.0.0@aar') {
    transitive = true
    exclude group: 'com.squareup.okhttp3', module: 'okhttp'
    exclude group: 'com.squareup.okhttp3', module: 'okhttp-urlconnection'
  }

  addUnimodulesDependencies([
          modulesPaths : [
                  '../../node_modules'
          ],
          configuration: 'api',
          target       : 'react-native',
          exclude      : [
                  // You can exclude unneeded modules here, e.g.,
                  // 'unimodules-face-detector-interface',
                  // 'expo-face-detector'

                  // Adding a name here will also remove the package
                  // from auto-generated BasePackageList.java
          ]
  ])

}

// This has to be down here for some reason
apply plugin: 'com.google.gms.google-services'

And my android build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
  repositories {
    google()
    jcenter()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.1.4'
    classpath 'com.google.gms:google-services:3.2.0'
    classpath 'de.undercouch:gradle-download-task:2.0.0'
  }
}

allprojects {
  repositories {
    // For non-detach
    maven {
      url "$rootDir/maven"
    }
    // For detach
    maven {
      url "$rootDir/../node_modules/expokit/maven"
    }
    maven {
      // We use a modified build of com.android.support.test:runner:1.0.1. Explanation in maven-test/README
      url "$rootDir/maven-test"
    }
    maven {
      url 'https://maven.google.com'
    }
    jcenter()
    maven {
      // Local Maven repo containing AARs with JSC built for Android
      url "$rootDir/../home/node_modules/jsc-android/android"
    }
    flatDir {
      dirs 'libs'
      // dirs project(':expoview').file('libs')
    }
    maven { url "https://jitpack.io" }

    // Want this last so that we never end up with a stale cache
    mavenLocal()
  }
}

task clean(type: Delete) {
  delete rootProject.buildDir
}

Please let me know if you need any more information.

@adamjnav Hi Adam. Sorry for tagging you, but I’ve been spending a week on upgrading to ExpoKit SDK 33, and have overcome a handful of issues myself. It feels like this is the last stretch, and it would be really great to have some help from the Expo team.

1 Like