klaxit / hidden-secrets-gradle-plugin

🔒 Deeply hide secrets on Android
MIT License
395 stars 40 forks source link

couldn't find "libsecrets.so" #40

Closed alexbgameson closed 3 years ago

alexbgameson commented 3 years ago

Hello!

Sorry about my last issue request.

I get this fatal error output in the logcat when running my java app:

2021-05-05 11:34:20.567 10645-10968/com.nanonodes.servers E/AndroidRuntime: FATAL EXCEPTION: Thread-13 Process: com.nanonodes.servers, PID: 10645 java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.nanonodes.servers-t6bctHCf0XzknxVEfyXDDw==/base.apk"],nativeLibraryDirectories=[/data/app/com.nanonodes.servers-t6bctHCf0XzknxVEfyXDDw==/lib/x86, /data/app/com.nanonodes.servers-t6bctHCf0XzknxVEfyXDDw==/base.apk!/lib/x86, /system/lib, /system/product/lib]]] couldn't find "libsecrets.so" at java.lang.Runtime.loadLibrary0(Runtime.java:1067) at java.lang.Runtime.loadLibrary0(Runtime.java:1007) at java.lang.System.loadLibrary(System.java:1667) at com.nanonodes.servers.Secrets.<clinit>(Secrets.kt:10) at com.nanonodes.servers.ui.login.PanelActivity$o.run(PanelActivity.java:1328) at java.lang.Thread.run(Thread.java:919)

App-level gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    // Enable NDK build
    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
        }
    }
    defaultConfig {
        applicationId "com.nanonodes.servers"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 22
        versionName 'v22'
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            debuggable false
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.annotation:annotation:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'com.google.firebase:firebase-auth:19.2.0'
    implementation 'com.google.android.gms:play-services-auth:17.0.0'
    implementation 'androidx.multidex:multidex:2.0.0'
    implementation 'com.google.android.gms:play-services-ads:18.2.0'
    implementation 'com.google.firebase:firebase-database:19.2.1'
    implementation 'com.firebase:firebase-client-android:2.5.0'
    implementation 'com.amitshekhar.android:android-networking:1.0.2'
    implementation 'com.anjlab.android.iab.v3:library:1.0.44'
    implementation 'com.android.billingclient:billing:2.1.0'
    implementation 'com.google.firebase:firebase-core:17.0.0'
    implementation 'com.github.javiersantos:PiracyChecker:1.2.7'
    implementation project(path: ':unity-ads')
    implementation files('libs/tapjoyconnectlibrary.jar')
    implementation 'com.scottyab:rootbeer-lib:0.0.8'
    implementation 'com.android.billingclient:billing:3.0.0'
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.michaelrocks.paranoid'
apply plugin: 'com.klaxit.hiddensecrets'
repositories {
    mavenCentral()
}

Project-level gradle:

buildscript {
    ext.kotlin_version = '1.5.0'
    repositories {
        google()
        jcenter()
        maven {
            url "https://jitpack.io"
        }
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.3'
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'io.michaelrocks:paranoid-gradle-plugin:0.2.5'
        classpath "com.klaxit.hiddensecrets:HiddenSecretsPlugin:0.1.2"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // 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"
        }
    }
}

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

As you can see I have added externalNativeBuild. I have also run the ./gradlew hideSecret -Pkey=yourKeyToObfuscate command in the terminal.

secrets.cpp, secrets.hpp, sha256.cpp, sha256.hpp are generated in the src/main/cpp folder along with the CMakeLists.txt I created manually.

ben-j69 commented 3 years ago

Hello @alexbgameson ,

why you have create manually the CMakeLists ? It should be done by the plugin.

The issue is closed, your problem is solved ?

andreluizreis commented 3 years ago

@ben-j69 , I started using the plugin today and I am facing the same issue. java.lang.UnsatisfiedLinkError: dlopen failed: library "libsecrets.so" not found

I followed the tutorial and checked if I could be doing something wrong but I didn't find why it is not creating the libsecrets.so. I added the gradle code for C++ code into my build.gradle (app) // Enable NDK build externalNativeBuild { cmake { path "src/main/cpp/CMakeLists.txt" } }

I have the folder app/src/main/cpp with 5 files: CMakeLists.txt, secrets.cpp, secrets.hpp, sha256.cpp, sha256.hpp.

Let me know if I have to open a new issue ticket.

ben-j69 commented 3 years ago

Hello @andreluizreis,

sorry for your issue. Can you confirm me you enabled the ndk build ?

 // Enable NDK build
    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
        }
    }
andreluizreis commented 3 years ago

@ben-j69 , Yes. I added it inside the android object after the defaultConfig in build.gradle(app). I downloaded the packages in the SDK Manager.

The Secrets.kt was created successfully. The problem is when I try to access the secret method, the app crashes.

andreluizreis commented 3 years ago

@ben-j69, to make it work. I needed to add to my build.gradle(app): android { defaultConfig { ndk { abiFilters 'armeabi-v7a', 'x86' } } } I don't know why it is not necessary for your project or why other users didn't have that problem.

Digging more into the problem. The CPP library is not being created for 64bits platforms. It is why when I add that code above it works. However, I can't publish this code without supporting 64bits. I don't know if it has a command to force CMAKE to build the 64 bits versions.

andreluizreis commented 3 years ago

@ben-j69, I found the solution for my issue. The NDK doesn't have the platform and it was giving problems to compile in 64-bits ABIs. So, when I updated the NDK to an older version it worked.