Skip to content

Getting java.lang.ClassNotFoundException #1036

@dotnetdreamer

Description

@dotnetdreamer

Please, provide the details below:

Did you verify this is a real problem by searching the NativeScript Forum and the other open issues in this repo?

Yes

Tell us about the problem

I have used one library here at https://search.maven.org/#artifactdetails%7Ccom.squareup.okhttp3%7Cbenchmarks%7C3.10.0%7Cjar but i am not able to succeed.

Please provide the following version numbers that your issue occurs with:

Did the error happen while the app was being constructed? (buildtime error)

No

Did the error happen while the app was executing? (runtime error)

Yes

Please tell us how to recreate the issue in as much detail as possible.

include.gradle:

android {
}
repositories {
    mavenCentral()
}

dependencies {
    compile "com.squareup.okhttp3:okhttp:3.10.0"
}

In the class:

declare const com: any;
   greet() {
        try {
            console.log(typeof com.squareup.okhttp.OkHttpClient);
            let client = new com.squareup.okhttp.OkHttpClient();
            let requestBody = new com.squareup.okhttp.MultipartBuilder()
                    .type(com.squareup.okhttp.MultipartBuilder.FORM)
                    // .addFormDataPart("file", file.getName(), 
                    //     com.squareup.okhttp.RequestBody.create(com.squareup.okhttp.MediaType.parse("text/csv"), file))
                    .addFormDataPart("firstName", "Idrees")
                    .build();
    
            let request = new com.squareup.okhttp.Request.Builder()
                    .url('http://localhost:10011/home/fileUpload')
                    .post(requestBody)
                    .build();
    
            client.newCall(request).enqueue(() => {
            });
    
        } catch (e) {
            console.log('-----------------error----------------');
            console.log(e);
        }
    }

But i am getting:

JS: -----------------error----------------
JS: Error: java.lang.ClassNotFoundException: com.squareup.okhttp.OkHttpClient
JS:     java.lang.Class.classForName(Native Method)
JS:     java.lang.Class.forName(Class.java:453)
JS:     java.lang.Class.forName(Class.java:378)
JS:     com.tns.Runtime.getClassForName(Runtime.java:1010)
JS:     com.tns.ClassResolver.resolveClass(ClassResolver.java:27)
JS:     com.tns.Runtime.resolveClass(Runtime.java:581)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1088)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:970)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:957)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:941)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:933)
JS:     com.tns.gen.java.lang.Runnable.run(Runnable.java:10)
JS:     android.os.Handler.handleCallback(Handler.java:789)
JS:     android.os.Handler.dispatchMessage(Handler.java:98)
JS:     android.os.Looper.loop(Looper.java:164)
JS:     android.app.ActivityThread.main(ActivityThread.java:6938)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
JS: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.squareup.okhttp.OkHttpClient" on path: DexPathList[[zip file "/data/app/org.nativescript.demong-tXcVa09BodDtVGlxcv9aLQ==/base.apk"],nativeLibraryDirectories=[/data/app/org.nativescript.demong-tXcVa09BodDtVGlxcv9aLQ==/lib/arm, /data/app/org.nativescript.demong-tXcVa09BodDtVGlxcv9aLQ==/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]

If i output the i am getting all the functions available with console.dir(com.squareup.okhttp.OkHttpClient):

JS: Address()
JS: Dns()
JS: CertificatePinner()
JS: Authenticator()JS: HttpUrl()
JS: Request()JS: Response()
JS: Cache()
JS: CacheControl()
JS: Headers()
JS: Call()
JS: OkHttpClient()
JS: Callback()
JS: Challenge()
JS: CipherSuite()
JS: Connection()
JS: Handshake()
JS: Protocol()
JS: Route()
JS: ConnectionPool()
JS: ConnectionSpec()
JS: TlsVersion()
JS: Credentials()
JS: Dispatcher()
JS: FormEncodingBuilder()
JS: RequestBody()
JS: Interceptor()
JS: MediaType()
JS: MultipartBuilder()
JS: OkUrlFactory()
JS: ResponseBody()
JS: benchmarks: {}
JS: internal: {
JS:   "io": {},
JS:   "http": {},
JS:   "tls": {},
JS:   "framed": {},
JS:   "huc": {},
JS:   "ws": {}
JS: }

i have attached the zip file here https://we.tl/ElgFxbQHx0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions