5

I am trying to build an old project using Android studio but the process fails. The error message I get is this:

Error:Failed to read native JSON data Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $

I get a more detailed error message in the Build tab:enter image description here

I believe that the build.gradle file of the app, is responsible for the error. The code of the file is:

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
    applicationId "com.example.despoina.ldtest"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    ndk {
        abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
    }
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    externalNativeBuild {
        cmake {
            arguments '-DANDROID_PLATFORM=android-13',
                    '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_static'
        }
    }
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

sourceSets {
    main {
        // let gradle pack the shared library into apk
        jniLibs.srcDirs += ['../gen-libs/gmp']
        jniLibs.srcDirs += ['../distribution/ecc/lib']
        jniLibs.srcDirs += ['../distribution/smodbus/lib']
        resources.includes = [ 'res/parameters.txt' ]
    }
}

externalNativeBuild {
    cmake {
        path 'src/main/cpp/CMakeLists.txt'
    }
}
}dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:25.2.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.1'
    // uncomment out this one to generate lib binaries,
    // and also uncommented out the one in settings.gradle
    // after lib is generated, just comment them out again
    //implementation project(':gen-libs')
}

Any help will be appreciated!!

Akshat Zala
  • 710
  • 1
  • 8
  • 23
despinac
  • 103
  • 1
  • 7
  • 2
    may be your json data is corrupted or the structure is changed, Check that again. – Amit K. Saha Jul 16 '18 at 14:39
  • Check this, it is similar to your question and its related to the android studio as well -- https://stackoverflow.com/questions/39918814/use-jsonreader-setlenienttrue-to-accept-malformed-json-at-line-1-column-1-path – codinnvrends Jun 24 '20 at 06:11

5 Answers5

2

Solution 1:

Finally I solved my problem which is not related to the json lenient mode, something wrong with my POST response (there some other non json output before the json data).

Here is the response from JakeWharton regarding how to set Gson lenient mode:

make sure that you have:compile 'com.google.code.gson:gson:2.6.1'

Gson gson = new GsonBuilder()
        .setLenient()
        .create();

Retrofit retrofit = new Retrofit.Builder()
        .baseUrl(BASE_URL)
        .client(client)
        .addConverterFactory(GsonConverterFactory.create(gson))
        .build();

Solution 2:

Also this issue occurred when the response contenttype is not application/json. In my case response content-type was text/html and i faced this problem. I changed it to application/json then it will work.

Muhammad Numan
  • 23,222
  • 6
  • 63
  • 80
0

An errore in Line 1 and Column 1 usually means that the JSON is not a real JSON. Maybe the Server is sending the JSON as HTML or something else or the format is not well readable (UTF-8 and ASCII are well supported, but other encoders may not). Try to print Server's response as byte[] and see which is the first char.

emandt
  • 2,547
  • 2
  • 16
  • 20
0

Maybe it same with: Can't build project, Gradle output tells Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $

It happened by error of Android Studio build configure, try to clean and rebuild your project again. If it still not working, you can copy your project to a new folder and reopen it by Android Studio.

dinhlam
  • 708
  • 3
  • 14
0

I think migrating the old project to current version being it Android Studio, Gradle plugin, Gradle built tool version is the best way to go. Unless you have any solid reason to stick around. Reason being, it is really difficult to have a match which works for an old version of Gradle plugin, build tools and Android Studio. Even if you find a fix to the mentioned error somehow, there is no guarantee that no further error occurs and build happens seamlessly.

If you still want a solution for the existing environment, you may get more clue by sharing the root build.gradle, gradle-wrapper properties etc. But IMHO better to migrate.

For migration, this may give you some idea if not solving the exact issue.

shanx
  • 415
  • 4
  • 10
0

I faced similar problem. I had to delete .cxx folder of my project to resolve it.