diff --git a/build.gradle b/build.gradle index e9d9cee..1e4b1bc 100755 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.0.0' + classpath 'com.android.tools.build:gradle:3.1.3' classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' } @@ -19,4 +19,4 @@ allprojects { task clean(type: Delete) { delete rootProject.buildDir -} +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a178cef..fbd131c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Oct 26 11:42:11 PDT 2017 +#Thu Jul 12 15:29:32 IST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/relinker/build.gradle b/relinker/build.gradle index a54cd0c..0543d98 100644 --- a/relinker/build.gradle +++ b/relinker/build.gradle @@ -6,8 +6,9 @@ group = 'com.getkeepsafe.relinker' version = '1.2.3' android { - compileSdkVersion 26 - buildToolsVersion "26.0.2" + compileSdkVersion 27 + buildToolsVersion "27.0.3" + compileOptions { sourceCompatibility JavaVersion.VERSION_1_6 targetCompatibility JavaVersion.VERSION_1_6 @@ -110,4 +111,4 @@ task javadocJar(type: Jar, dependsOn: javadoc) { artifacts { archives sourcesJar archives javadocJar -} +} \ No newline at end of file diff --git a/relinker/src/main/java/com/getkeepsafe/relinker/ApkLibraryInstaller.java b/relinker/src/main/java/com/getkeepsafe/relinker/ApkLibraryInstaller.java index 6d6924c..c9a9073 100644 --- a/relinker/src/main/java/com/getkeepsafe/relinker/ApkLibraryInstaller.java +++ b/relinker/src/main/java/com/getkeepsafe/relinker/ApkLibraryInstaller.java @@ -17,6 +17,7 @@ import android.content.Context; import android.content.pm.ApplicationInfo; +import android.text.TextUtils; import java.io.Closeable; import java.io.File; @@ -68,6 +69,8 @@ public void installLibrary(final Context context, ZipEntry libraryEntry = null; for (final String abi : abis) { + if (TextUtils.isEmpty(abi)) continue; + jniNameInApk = "lib" + File.separatorChar + abi + File.separatorChar + mappedLibraryName; libraryEntry = zipFile.getEntry(jniNameInApk); diff --git a/relinker/src/main/java/com/getkeepsafe/relinker/ReLinker.java b/relinker/src/main/java/com/getkeepsafe/relinker/ReLinker.java index 95fa2d2..59feff1 100755 --- a/relinker/src/main/java/com/getkeepsafe/relinker/ReLinker.java +++ b/relinker/src/main/java/com/getkeepsafe/relinker/ReLinker.java @@ -24,6 +24,7 @@ * to Android's inability to properly install / load native libraries for Android versions before * API 21 */ +@SuppressWarnings("WeakerAccess") public class ReLinker { public interface LoadListener { void success(); @@ -70,6 +71,14 @@ public static void loadLibrary(final Context context, new ReLinkerInstance().loadLibrary(context, library, version, listener); } + public static ReLinkerInstance with(final ReLinker.LibraryLoader libraryLoader) { + return new ReLinkerInstance(libraryLoader); + } + + public static ReLinkerInstance with(final ReLinker.LibraryInstaller libraryInstaller) { + return new ReLinkerInstance(libraryInstaller); + } + public static ReLinkerInstance force() { return new ReLinkerInstance().force(); } @@ -83,4 +92,4 @@ public static ReLinkerInstance recursively() { } private ReLinker() {} -} +} \ No newline at end of file diff --git a/relinker/src/main/java/com/getkeepsafe/relinker/ReLinkerInstance.java b/relinker/src/main/java/com/getkeepsafe/relinker/ReLinkerInstance.java index feb5233..071561b 100755 --- a/relinker/src/main/java/com/getkeepsafe/relinker/ReLinkerInstance.java +++ b/relinker/src/main/java/com/getkeepsafe/relinker/ReLinkerInstance.java @@ -16,6 +16,7 @@ package com.getkeepsafe.relinker; import android.content.Context; +import android.text.TextUtils; import android.util.Log; import com.getkeepsafe.relinker.elf.ElfParser; @@ -28,6 +29,7 @@ import java.util.Locale; import java.util.Set; +@SuppressWarnings({"unused", "WeakerAccess"}) public class ReLinkerInstance { private static final String LIB_DIR = "lib"; @@ -43,6 +45,14 @@ protected ReLinkerInstance() { this(new SystemLibraryLoader(), new ApkLibraryInstaller()); } + protected ReLinkerInstance(final ReLinker.LibraryLoader libraryLoader) { + this(libraryLoader, new ApkLibraryInstaller()); + } + + protected ReLinkerInstance(final ReLinker.LibraryInstaller libraryInstaller) { + this(new SystemLibraryLoader(), libraryInstaller); + } + protected ReLinkerInstance(final ReLinker.LibraryLoader libraryLoader, final ReLinker.LibraryInstaller libraryInstaller) { if (libraryLoader == null) { @@ -188,9 +198,12 @@ private void loadLibraryInternal(final Context context, try { parser = new ElfParser(workaroundFile); dependencies = parser.parseNeededDependencies(); - }finally { - parser.close(); + } finally { + if (parser != null) { + parser.close(); + } } + for (final String dependency : dependencies) { loadLibrary(context, libraryLoader.unmapLibraryName(dependency)); } @@ -259,6 +272,7 @@ public boolean accept(File dir, String filename) { for (final File file : existingFiles) { if (force || !file.getAbsolutePath().equals(workaroundFile.getAbsolutePath())) { + //noinspection ResultOfMethodCallIgnored file.delete(); } } @@ -273,4 +287,4 @@ public void log(final String message) { logger.log(message); } } -} +} \ No newline at end of file diff --git a/relinker/src/main/java/com/getkeepsafe/relinker/SystemLibraryLoader.java b/relinker/src/main/java/com/getkeepsafe/relinker/SystemLibraryLoader.java index e661321..2aa8dc1 100755 --- a/relinker/src/main/java/com/getkeepsafe/relinker/SystemLibraryLoader.java +++ b/relinker/src/main/java/com/getkeepsafe/relinker/SystemLibraryLoader.java @@ -1,12 +1,12 @@ /** * Copyright 2015 - 2016 KeepSafe Software, Inc. - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + *

* http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,15 +15,22 @@ */ package com.getkeepsafe.relinker; +import android.annotation.SuppressLint; +import android.annotation.TargetApi; import android.os.Build; +import android.text.TextUtils; + +import static android.os.Build.VERSION.SDK_INT; +import static android.os.Build.VERSION_CODES.LOLLIPOP; + +public class SystemLibraryLoader implements ReLinker.LibraryLoader { -@SuppressWarnings("deprecation") -final class SystemLibraryLoader implements ReLinker.LibraryLoader { @Override public void loadLibrary(final String libraryName) { System.loadLibrary(libraryName); } + @SuppressLint("UnsafeDynamicallyLoadedCode") @Override public void loadPath(final String libraryPath) { System.load(libraryPath); @@ -47,12 +54,16 @@ public String unmapLibraryName(String mappedLibraryName) { @Override public String[] supportedAbis() { - if (Build.VERSION.SDK_INT >= 21 && Build.SUPPORTED_ABIS.length > 0) { - return Build.SUPPORTED_ABIS; - } else if (!TextUtils.isEmpty(Build.CPU_ABI2)) { - return new String[] {Build.CPU_ABI, Build.CPU_ABI2}; - } else { - return new String[] {Build.CPU_ABI}; - } + return SDK_INT >= LOLLIPOP ? getSupportedAbis_21() : getSupportedAbisOlder(); + } + + @TargetApi(LOLLIPOP) + private String[] getSupportedAbis_21() { + final String[] abis = Build.SUPPORTED_ABIS; + return abis != null && abis.length > 0 ? abis : getSupportedAbisOlder(); + } + + private String[] getSupportedAbisOlder() { + return new String[]{Build.CPU_ABI, Build.CPU_ABI2}; } -} +} \ No newline at end of file diff --git a/relinker/src/main/java/com/getkeepsafe/relinker/TextUtils.java b/relinker/src/main/java/com/getkeepsafe/relinker/TextUtils.java deleted file mode 100755 index b737d8f..0000000 --- a/relinker/src/main/java/com/getkeepsafe/relinker/TextUtils.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright 2015 - 2016 KeepSafe Software, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.getkeepsafe.relinker; - -/** - * Slimmed down version of https://developer.android.com/reference/android/text/TextUtils.html to - * avoid depending on android.text.TextUtils. - */ -final class TextUtils { - /** - * Returns true if the string is null or 0-length. - * - * @param str the string to be examined - * @return true if str is null or zero length - */ - public static boolean isEmpty(CharSequence str) { - return str == null || str.length() == 0; - } -} diff --git a/sample/build.gradle b/sample/build.gradle index 856133f..2055d81 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -5,8 +5,8 @@ repositories { } android { - compileSdkVersion 26 - buildToolsVersion "26.0.2" + compileSdkVersion 27 + buildToolsVersion "27.0.3" sourceSets { main { @@ -18,7 +18,7 @@ android { applicationId "com.getkeepsafe.relinker.sample" //noinspection MinSdkTooLow minSdkVersion 9 - targetSdkVersion 26 + targetSdkVersion 27 versionCode 1 versionName "1.0" } @@ -31,7 +31,6 @@ android { } dependencies { - compile project(':relinker') - testCompile 'junit:junit:4.12' -} - + implementation project(':relinker') + testImplementation 'junit:junit:4.12' +} \ No newline at end of file