Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #47 #48

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand All @@ -19,4 +19,4 @@ allprojects {

task clean(type: Delete) {
delete rootProject.buildDir
}
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions relinker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -110,4 +111,4 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
artifacts {
archives sourcesJar
archives javadocJar
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion relinker/src/main/java/com/getkeepsafe/relinker/ReLinker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand All @@ -83,4 +92,4 @@ public static ReLinkerInstance recursively() {
}

private ReLinker() {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";

Expand All @@ -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) {
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -273,4 +287,4 @@ public void log(final String message) {
logger.log(message);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* Copyright 2015 - 2016 KeepSafe Software, Inc.
*
* <p>
* 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
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* 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.
Expand All @@ -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);
Expand All @@ -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};
}
}
}
32 changes: 0 additions & 32 deletions relinker/src/main/java/com/getkeepsafe/relinker/TextUtils.java

This file was deleted.

13 changes: 6 additions & 7 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ repositories {
}

android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
compileSdkVersion 27
buildToolsVersion "27.0.3"

sourceSets {
main {
Expand All @@ -18,7 +18,7 @@ android {
applicationId "com.getkeepsafe.relinker.sample"
//noinspection MinSdkTooLow
minSdkVersion 9
targetSdkVersion 26
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
Expand All @@ -31,7 +31,6 @@ android {
}

dependencies {
compile project(':relinker')
testCompile 'junit:junit:4.12'
}

implementation project(':relinker')
testImplementation 'junit:junit:4.12'
}