For me, the best approach is if you want your library to remain autonomous (without involving a network to check or download fragments of the library, I mean), it would be mandatory to use an initializer class that will receive a token from the client application.
It will be crackable , since the token test will be executed by your lib: one can change the lib in the way, it will just skip this test, but it will be difficult due to obfuscation, But this is probably enough if you are not using your library without registration, this is a really important issue.
This will prevent lib from working if passcodenot true.
You can make obfuscation more effective by avoiding this:
public void initLib(String passcode) {
if (passcode == A_GIVEN_PUBLIC_STATIC_THAT_STORESTHE_CODE) {
}
else {
throw new RuntimeException("Bad passcode, sorry!");
}
}
But instead:
public void initLib(String passcode) {
final char[] PASS_ENCRYPTED = "f5uhjgf56ik8kv214d5".toCharArray();
final char[] PASS_MINUSMASK = "bc".toCharArray();
final int PASS_SHIFT = 11;
final int PASS_MASK_MINUS = 2;
for (int ctr = 0; ctr < PASS_MINUSMASK.length; ++ctr) {
final char next = PASS_ENCRYPTED[PASS_SHIFT + ctr - PASS_MASK_MINUS];
if (passcode.charAt(ctr) != next - (PASS_MINUSMASK[ctr] - 'a')) {
return;
}
}
}
, , . ( "" ), , .
, , , - , , . IMEI - .
, . .
, , . , "" , , , . " ", (, , ), , .