Okhttp is unresolved in Android SDK

Calling init() in my kotlin app crashes the app immediately. This is the only particle function I call so far, to test I have all the dependencies. I’m working in kotlin.

I followed the stack trace to the library, where okhttp is unresolved . It is highlighted red, as is every http parsing function in the library itself. Is the Android SDK setup page up to date? The repo hasn’t been touched in quite a while.

Reverting to 0.5.1 has the app working, but I would really like to use the newest SDK.
My build.gradle file:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'com.google.secrets_gradle_plugin' version '0.5'

}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.masterandroid.meg"
        minSdkVersion 22
        targetSdkVersion 30
        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 JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    implementation 'com.squareup.okhttp3:okhttp:4.9.0'
    implementation 'io.particle:cloudsdk:0.5.1'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    implementation 'com.google.android.gms:play-services-maps:17.0.1'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9")
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
}

There are definitely some dependencies that aren’t really needed, I just included everything hoping I would eventually include the required set. I was able to add okhttp3 and reference the broken SDK functions in my main activity just to test if the squareup repo was broken.

My android manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.masterandroid.meg">
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application

        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/Theme.MEG">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <uses-library
            android:name="org.apache.http.legacy"
            android:required="false" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="${MAPS_API_KEY}" />
    </application>

</manifest>

I included the permissions that worked last time I needed the particle API, but they didn’t help with the latest release. I went back to 1.0.0 and the issue remains.

Any ideas what could be going wrong? Thanks everybody!

Could you please provide the errors you’re getting.

1 Like

The error is below. Android Studio offered to decompile the ParticleCloudSDK library when I click on the error message “at io.particle.android.sdk.cloud.ParticleCloudSDK.init(ParticleCloudSDK.java:27)”.
As I said before, everything that has to do with okhttp is unresolveable.

The import line in the library is line 7, import com.squareup.okhttp.HttpUrl; Hovering over the red okhttp text gives the message cannot resolve symbol 'okhttp'.

2021-10-12 23:24:19.118 5212-5212/com.masterandroid.sdktest E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.masterandroid.sdktest, PID: 5212
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/okhttp/HttpUrl;
        at io.particle.android.sdk.cloud.ParticleCloudSDK.initWithInstanceCheck(ParticleCloudSDK.java:48)
        at io.particle.android.sdk.cloud.ParticleCloudSDK.init(ParticleCloudSDK.java:27)
        at com.masterandroid.sdktest.MainActivity.onCreate(MainActivity.kt:11)
        at android.app.Activity.performCreate(Activity.java:7963)
        at android.app.Activity.performCreate(Activity.java:7952)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3629)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:8167)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.squareup.okhttp.HttpUrl" on path: DexPathList[[zip file "/data/app/com.masterandroid.sdktest-pV8Bo8Zv8vEHFD9yEicpyg==/base.apk"],nativeLibraryDirectories=[/data/app/com.masterandroid.sdktest-pV8Bo8Zv8vEHFD9yEicpyg==/lib/arm64, /system/lib64, /system/product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at io.particle.android.sdk.cloud.ParticleCloudSDK.initWithInstanceCheck(ParticleCloudSDK.java:48) 
        at io.particle.android.sdk.cloud.ParticleCloudSDK.init(ParticleCloudSDK.java:27) 
        at com.masterandroid.sdktest.MainActivity.onCreate(MainActivity.kt:11) 
        at android.app.Activity.performCreate(Activity.java:7963) 
        at android.app.Activity.performCreate(Activity.java:7952) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3629) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:237) 
        at android.app.ActivityThread.main(ActivityThread.java:8167) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100) 

Replied below, thanks for taking a look!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.