StringCare / AndroidLibrary

Android library to reveal or obfuscate strings and assets at runtime
Apache License 2.0
247 stars 44 forks source link

java.lang.NoClassDefFoundError: Could not initialize class components.Stark #60

Closed efraespada closed 4 years ago

efraespada commented 5 years ago

Just cloning this repo and building the project, we get this error:

java.lang.NoClassDefFoundError: Could not initialize class components.Stark
efraespada commented 5 years ago

@ilyasdirin I cloned the repo again. The sample project is building without problems on my computer. Have you tried to invalidate the Android Studio cache and restart it?

ilyasdirin commented 5 years ago

@ilyasdirin I cloned the repo again. The sample project is building without problems on my computer. Have you tried to invalidate the Android Studio cache and restart it?

@efraespada I tried many times with clear, invalidate even macbook restart. I think it may uses some kind of java library because when I build it in windows it asks for java permission. can that libraries may be missing in mac?

efraespada commented 5 years ago

It shouldn't. The SC plugin uses native libraries (dll and dylib), which are loaded in the Stark class. Dependencies on plugin:

dependencies {
    implementation gradleApi()
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    implementation group: 'com.google.guava', name: 'guava', version: '28.0-jre'
    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile group: 'org.mockito', name: 'mockito-core', version: '2.1.0'
}

The stranger thing is that it is not working in both systems (Windows - MacOS).

efraespada commented 5 years ago

@ilyasdirin did you build the app with ProGuard or R8 enabled?

ilyasdirin commented 5 years ago

@efraespada no I do not build app with ProGuard or R8. But if I achieve to build it I will eventually use it with proguard but for now I am not able to build it without proguard and R8.

jiriklobasa commented 5 years ago

Did you find a solution to overcome this error @ilyasdirin? Same happens to me with the latest version 3.5, tried on Mac OS 10.13.6 with Android Studio 3.5.1. Any ideas @efraespada ? I have noticed that it happens just when you specify stringFilesoption.

efraespada commented 5 years ago

Hi @jiriklobasa

Does this error only happen when stringFiles property is defined?

Are you getting any other error like this one?

Caused by: java.lang.UnsatisfiedLinkError: /private/var/folders/_t/ppptr4fs06gg1f38_bctzh3m0000gn/T/libsignKey.dylib5689898627273585595: dlopen(/private/var/folders/_t/ppptr4fs06gg1f38_bctzh3m0000gn/T/libsignKey.dylib5689898627273585595, 1): Symbol not found: __ZN5boost6system6detail24system_category_instanceE
  Referenced from: /private/var/folders/_t/ppptr4fs06gg1f38_bctzh3m0000gn/T/libsignKey.dylib5689898627273585595
  Expected in: /usr/local/opt/boost/lib/libboost_system.dylib
 in /private/var/folders/_t/ppptr4fs06gg1f38_bctzh3m0000gn/T/libsignKey.dylib5689898627273585595
jiriklobasa commented 5 years ago

Hey @efraespada, yeah, from time to time this also appears. But when you clean the project up and rebuild it always ends with the java.lang.NoClassDefFoundError: Could not initialize class components.Stark error. Just to add the statement - stringFiles property does not have impact on the error. You can just simply put an entry in strings.xml file with hidden="true" attribute and it crashes.

klozMobile commented 4 years ago

Hi @jiriklobasa

Does this error only happen when stringFiles property is defined?

Are you getting any other error like this one?

Caused by: java.lang.UnsatisfiedLinkError: /private/var/folders/_t/ppptr4fs06gg1f38_bctzh3m0000gn/T/libsignKey.dylib5689898627273585595: dlopen(/private/var/folders/_t/ppptr4fs06gg1f38_bctzh3m0000gn/T/libsignKey.dylib5689898627273585595, 1): Symbol not found: __ZN5boost6system6detail24system_category_instanceE
  Referenced from: /private/var/folders/_t/ppptr4fs06gg1f38_bctzh3m0000gn/T/libsignKey.dylib5689898627273585595
  Expected in: /usr/local/opt/boost/lib/libboost_system.dylib
 in /private/var/folders/_t/ppptr4fs06gg1f38_bctzh3m0000gn/T/libsignKey.dylib5689898627273585595

I do

efraespada commented 4 years ago

@klozMobile are you using a macOS system? If that's the case, have you recently upgrade your system?

MostafaAnter commented 4 years ago
Screen Shot 2019-12-30 at 4 26 13 PM

Same problem with me

MostafaAnter commented 4 years ago

@efraespada yes I'm using macOS catalina

MostafaAnter commented 4 years ago

after many trying, I think this problem com when to add cpp folder and add some native code to project I think there is some conflict with your project native code and our project I hope that help thanks in advanced

efraespada commented 4 years ago

@MostafaAnter you are right. I've created a native C++ project and added SC. It returns the java.lang.UnsatisfiedLinkError error at runtime.

SC uses the default name for the native library (native-lib) and your native library overrides it.

I've just released v3.6.2 with a different native library name.

Thank you so much @MostafaAnter for your report 🙌


@jiriklobasa @klozMobile @ilyasdirin do you have a similar project case?

MostafaAnter commented 4 years ago

@efraespada so far so good now I can reveal and obfuscate any text on kotlin files but I still can't do hidden to my strings on res folder so this error show to me Library not loaded: /usr/local/opt/boost/lib/libboost_system.dylib Screen Shot 2019-12-31 at 11 58 11 AM now I guess that is happened because of JDK on my device, so there is any suggestions

efraespada commented 4 years ago

I think It's an error on the G++ compiler flags, some native libraries were not included in the SC native lib for macOS systems. @MostafaAnter try with v3.6.3.

guillermog888 commented 4 years ago

Hi @efraespada, I have the same problem and I downloaded v3.6.3 but I have the same error whit v3.6.2

Library not loaded: /usr/local/opt/boost/lib/libboost_system.dylib Referenced from: /private/var/folders/rd/d5t6kngn69b4czf58f_8cxtr0000gn/T/libsignKey.dylib682191099424347482

efraespada commented 4 years ago

Could you try v4.0.0? There is a new implementation, the plugin is applied per module:

apply plugin: 'com.android.application'
apply plugin: StringCare

stringcare {
    debug true
    assetsFiles = ["*.json"]
    stringFiles = ['strings.xml']
    srcFolders = ['src/main']
}

android {
    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
}

repositories {
    jcenter()
}

dependencies {
    implementation "com.stringcare:library:$stringcare_version"
}
guillermog888 commented 4 years ago

Hi @efraespada the v4.0.0 works for me but i have one question im trying to obfuscate the strings but the project have different project modules and i can't obfuscate the string of the others modules thanks

efraespada commented 4 years ago

@guillermog888 I think that's because the plugin only controls (by the moment) the application module:

apply plugin: 'com.android.application'
apply plugin: StringCare

I'll try to fix that.

efraespada commented 4 years ago

@guillermog888 I've created another issue with that problem:

- Library Support

I close this one.

haitv2910 commented 3 years ago

Hi @efraespada, I have the same problem and I downloaded v4.2.1 but I have the same error whit v4.2.1 I'm using macOS

efraespada commented 3 years ago

@haitv2910 in which modules you were using Stringcare?