terl / lazysodium-android

An Android implementation of the Libsodium cryptography library. For the lazy dev.
https://github.com/terl/lazysodium-java/wiki
Mozilla Public License 2.0
108 stars 25 forks source link

Failing on compile with error "Class file for com.sun.jna.NativeLong not found" #20

Closed Isometries closed 5 years ago

Isometries commented 5 years ago

The full compile error is

error: cannot access NativeLong
class file for com.sun.jna.NativeLong not found

app build.gradle file is set up like this:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.ultralord.myapplication"
        minSdkVersion 22
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
//    sourceSets { main { jni.srcDirs = ['src/jniLibs/'] } }
}

dependencies {
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:design:27.1.1'
    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.github.chrisbanes:PhotoView:2.1.4'
    implementation "com.goterl.lazycode:lazysodium-android:3.6.2@aar"
    implementation "net.java.dev.jna:jna:5.2.0@arr"
}

I've tried other versions of jna and the error is the same.

gurpreet- commented 5 years ago

I tested this in the app and you're correct, it fails.

I have recently changed the scope of the JNA dependency so this is a regression.

I have fixed this in 3.6.3, please upgrade to that. Something like this should work:

dependencies {
   implementation "com.goterl.lazycode:lazysodium-android:3.6.3@aar"
   implementation "net.java.dev.jna:jna:5.3.1@aar"
}
Isometries commented 5 years ago

Unfortunately I've done as you suggested and still encounter the same error. I'm wondering if there's a conflict in my build.gradle file?

Here is my upper level:


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

buildscript {

    repositories {
        google()
        jcenter()
        maven {
            url "https://dl.bintray.com/terl/lazysodium-maven"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://jitpack.io"
        }
        maven {
            url  "https://dl.bintray.com/terl/lazysodium-maven"
        }
    }
}

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

and lower level

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.tgabriel.CryptoGallery"
        minSdkVersion 22
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
//    sourceSets { main { jni.srcDirs = ['src/jniLibs/'] } }
}

dependencies {
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:design:27.1.1'
    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.github.chrisbanes:PhotoView:2.1.4'
    implementation "com.goterl.lazycode:lazysodium-android:3.6.3@aar"
    implementation "net.java.dev.jna:jna:5.3.1@arr"
}
gurpreet- commented 5 years ago

Hi @Isometries,

Shouldn't it be implementation "net.java.dev.jna:jna:5.3.1@aar" rather than implementation "net.java.dev.jna:jna:5.3.1@arr"?

Isometries commented 5 years ago

Yes, that was my mistake. The issue seems to be corrected.