Android SDK Initialization Error


#1

I am starting an android app project using Particle Android SDK, but every time I run the simple app in the emulator that initializes the SDK using

ParticleCloudSDK.init(this);
in onCreate method, I get this error.

java.lang.BootstrapMethodError: Exception from call site #5 bootstrap method
        at io.particle.android.sdk.cloud.ApiFactory.buildNewCloudApi(ApiFactory.java:75)
        at io.particle.android.sdk.cloud.SDKProvider.(SDKProvider.java:48)
        at io.particle.android.sdk.cloud.ParticleCloudSDK.initWithParams(ParticleCloudSDK.java:47)
        at io.particle.android.sdk.cloud.ParticleCloudSDK.init(ParticleCloudSDK.java:24)
        at com.example.putra.myapplication.MainActivity.onCreate(MainActivity.java:16)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 Caused by: java.lang.ClassCastException: Bootstrap method returned null
        at io.particle.android.sdk.cloud.ApiFactory.buildNewCloudApi(ApiFactory.java:75) 
        at io.particle.android.sdk.cloud.SDKProvider.(SDKProvider.java:48) 
        at io.particle.android.sdk.cloud.ParticleCloudSDK.initWithParams(ParticleCloudSDK.java:47) 
        at io.particle.android.sdk.cloud.ParticleCloudSDK.init(ParticleCloudSDK.java:24) 
        at com.example.putra.myapplication.MainActivity.onCreate(MainActivity.java:16) 
        at android.app.Activity.performCreate(Activity.java:7136) 
        at android.app.Activity.performCreate(Activity.java:7127) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6669) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 

This is my build.gradle app module


apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.putra.myapplication"
        minSdkVersion 26
        targetSdkVersion 28
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'io.particle:devicesetup:0.5.3'
    implementation 'io.particle:cloudsdk:0.5.0'

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:recyclerview-v7:28.0.0-alpha3'
    implementation 'com.android.support:multidex:1.0.3'

}

My friend who works on the same project also has the same issue in initializing Particle Android SDK, some help will be very appreciated.


#2

what is in your onCreate function in MainActivity.java (if you didnt change activity name)?


#3

Hello, I only use empty activity and all code is generated automatically when we start the project. The only thing I added is the Particle SDK initialization function.


package com.example.putra.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import io.particle.android.sdk.cloud.ParticleCloudSDK;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Code that I added
        ParticleCloudSDK.init(this);
    }
}

I referenced Toglefritz Lair’s blog, and this is the first step I need to take to use the SDK


#4

@VitusP To use our libraries you will need to target Java 8 with your project.

Add these lines to your build gradle.

compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
}

#5

Thank you! I previously thought that Android Studio will automatically compile with the Java 8 I installed on my computer.