Proguard/R8 annotations
Prevent R8 dead-code and obfuscation for the classes that JNI native code expects to find.
This commit is contained in:
Родитель
4b61c77d2f
Коммит
771561987b
|
@ -19,9 +19,12 @@ android {
|
|||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
minifyEnabled true
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
debug {
|
||||
minifyEnabled false
|
||||
}
|
||||
}
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
|
|
|
@ -1,35 +1,56 @@
|
|||
package com.microsoft.applications.events.maesdktest;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.microsoft.applications.events.HttpClient;
|
||||
import com.microsoft.applications.events.OfflineRoom;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
// Used to load the 'native-lib' library on application startup.
|
||||
static {
|
||||
System.loadLibrary("native-lib");
|
||||
System.loadLibrary("maesdk");
|
||||
}
|
||||
class DummyLogger extends MaeUnitLogger {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
m_client = new HttpClient(getApplicationContext());
|
||||
// Example of a call to a native method
|
||||
TextView tv = findViewById(R.id.sample_text);
|
||||
tv.setText("Fun Times " + stringFromJNI(System.getProperty("java.io.tmpdir")));
|
||||
void log_failure(String filename, int line, String summary) {
|
||||
Log.e("MAE", String.format("Uh oh %s: %s", filename, summary));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A native method that is implemented by the 'native-lib' native library,
|
||||
* which is packaged with this application.
|
||||
*/
|
||||
public native String stringFromJNI(String path);
|
||||
HttpClient m_client;
|
||||
// Used to load the 'native-lib' library on application startup.
|
||||
static {
|
||||
System.loadLibrary("native-lib");
|
||||
System.loadLibrary("maesdk");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
m_client = new HttpClient(getApplicationContext());
|
||||
OfflineRoom.connectContext(getApplicationContext());
|
||||
TestStub testStub = new TestStub();
|
||||
DummyLogger dummyLogger = new DummyLogger();
|
||||
// Example of a call to a native method
|
||||
TextView tv = findViewById(R.id.sample_text);
|
||||
try {
|
||||
Integer result = testStub.executorRun(dummyLogger);
|
||||
tv.setText(String.format("Tests returned %d", result));
|
||||
}
|
||||
catch(ExecutionException e) {
|
||||
tv.setText("Woopsy");
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
tv.setText("Interrupted!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A native method that is implemented by the 'native-lib' native library, which is packaged with
|
||||
* this application.
|
||||
*/
|
||||
public native String stringFromJNI(String path);
|
||||
|
||||
HttpClient m_client;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,38 @@
|
|||
package com.microsoft.applications.events.maesdktest;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
public class TestStub {
|
||||
class CallTests implements Callable<Integer> {
|
||||
MaeUnitLogger logger;
|
||||
|
||||
CallTests(MaeUnitLogger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a result, or throws an exception if unable to do so.
|
||||
*
|
||||
* @return computed result
|
||||
* @throws Exception if unable to compute a result
|
||||
*/
|
||||
@Override
|
||||
public Integer call() throws Exception {
|
||||
return Integer.valueOf(runNativeTests(logger));
|
||||
}
|
||||
}
|
||||
|
||||
public Integer executorRun(MaeUnitLogger logger) throws ExecutionException, InterruptedException {
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(2);
|
||||
|
||||
FutureTask<Integer> tests = new FutureTask<Integer>(new CallTests(logger));
|
||||
executorService.execute(tests);
|
||||
return tests.get();
|
||||
}
|
||||
|
||||
public native int runNativeTests(MaeUnitLogger logger);
|
||||
}
|
|
@ -41,6 +41,7 @@ android {
|
|||
}
|
||||
debug {
|
||||
jniDebuggable true
|
||||
minifyEnabled true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package com.microsoft.applications.events;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
@Keep
|
||||
public class ByTenant {
|
||||
public String tenantToken;
|
||||
public long count;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.microsoft.applications.events;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -17,6 +18,7 @@ public class EventProperty {
|
|||
return m_category;
|
||||
}
|
||||
|
||||
@Keep
|
||||
public EventPropertyValue getEventPropertyValue() {
|
||||
return m_eventPropertyValue;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package com.microsoft.applications.events;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
@Keep
|
||||
abstract class EventPropertyValue {
|
||||
private EventPropertyType m_type;
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import android.os.Build;
|
|||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
@ -175,6 +176,21 @@ class Request implements Runnable {
|
|||
public class HttpClient {
|
||||
private static final int MAX_HTTP_THREADS = 2; // Collector wants no more than 2 at a time
|
||||
|
||||
/**
|
||||
* Shim FutureTask: we would like to @Keep the cancel method for JNI
|
||||
*/
|
||||
class FutureShim extends FutureTask<Boolean> {
|
||||
FutureShim(Request inner) {
|
||||
super(inner, true);
|
||||
}
|
||||
|
||||
@Keep
|
||||
@Override
|
||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||
return super.cancel(mayInterruptIfRunning);
|
||||
}
|
||||
}
|
||||
|
||||
public HttpClient(Context context)
|
||||
{
|
||||
m_context = context;
|
||||
|
@ -313,16 +329,18 @@ public class HttpClient {
|
|||
|
||||
public native void dispatchCallback(String id, int response, Object[] headers, byte[] body);
|
||||
|
||||
@Keep
|
||||
public FutureTask<Boolean> createTask(String url, String method, byte[] body, String request_id, int[] header_index,
|
||||
byte[] header_buffer) {
|
||||
try {
|
||||
Request r = new Request(this, url, method, body, request_id, header_index, header_buffer);
|
||||
return new FutureTask<>(r, true);
|
||||
return new FutureShim(r);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Keep
|
||||
public void executeTask(FutureTask<Boolean> t) {
|
||||
m_executor.execute(t);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||
import android.database.Cursor;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
|
@ -12,6 +13,7 @@ import java.util.Map;
|
|||
import java.util.TreeMap;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@Keep
|
||||
public class OfflineRoom implements AutoCloseable {
|
||||
class TrimTransaction implements Callable<Long>
|
||||
{
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package com.microsoft.applications.events;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.room.Database;
|
||||
import androidx.room.RoomDatabase;
|
||||
|
||||
@Keep
|
||||
@Database(version = 3, entities = { StorageRecord.class, StorageSetting.class })
|
||||
public abstract class OfflineRoomDatabase extends RoomDatabase {
|
||||
abstract public StorageRecordDao getStorageRecordDao();
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package com.microsoft.applications.events;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.ColumnInfo;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.Index;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
@Keep
|
||||
@Entity(indices = {@Index(value = {"id"}, unique = true)})
|
||||
public class StorageRecord {
|
||||
final public static int EventLatency_Unspecified = -1;
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.microsoft.applications.events;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
@Keep
|
||||
@Entity
|
||||
public class StorageSetting {
|
||||
@PrimaryKey
|
||||
|
|
Загрузка…
Ссылка в новой задаче