Skip to content

Commit 39f1281

Browse files
authored
Merge pull request #758 from mixpanel/upgrade-target-sdk
Upgrade targetSdkVersion to 30
2 parents 3995cd3 + 585810f commit 39f1281

36 files changed

+503
-4295
lines changed

.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
4+
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
5+
<classpathentry kind="output" path="bin/default"/>
6+
</classpath>

.github/workflows/android.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ jobs:
1313
- name: Checkout the code
1414
uses: actions/checkout@v2
1515
- name: Run Unit test
16-
uses: reactivecircus/android-emulator-runner@v2
16+
uses: reactivecircus/android-emulator-runner@v2.20.0
1717
with:
18-
api-level: 27
18+
api-level: 30
19+
profile: Nexus 6
20+
arch: x86_64
1921
script: ./gradlew createDebugCoverageReport
2022
- name: Lint
2123
run: ./gradlew lint

.project

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>mixpanel-android</name>
4+
<comment>Project mixpanel-android created by Buildship.</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
22+
</natures>
23+
<filteredResources>
24+
<filter>
25+
<id>1633027344058</id>
26+
<name></name>
27+
<type>30</type>
28+
<matcher>
29+
<id>org.eclipse.core.resources.regexFilterMatcher</id>
30+
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
31+
</matcher>
32+
</filter>
33+
</filteredResources>
34+
</projectDescription>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
arguments=
2+
auto.sync=false
3+
build.scans.enabled=false
4+
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
5+
connection.project.dir=
6+
eclipse.preferences.version=1
7+
gradle.user.home=
8+
java.home=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
9+
jvm.arguments=
10+
offline.mode=false
11+
override.workspace.settings=true
12+
show.console.view=true
13+
show.executions.view=true

build.gradle

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
buildscript {
22
repositories {
3-
jcenter()
3+
mavenCentral()
44
google()
55
}
66
dependencies {
7-
classpath 'com.android.tools.build:gradle:3.3.1'
7+
classpath 'com.android.tools.build:gradle:4.1.1'
88
}
99
}
1010

@@ -17,19 +17,25 @@ group = GROUP
1717
version = VERSION_NAME
1818

1919
android {
20-
compileSdkVersion 27
21-
buildToolsVersion '28.0.3'
20+
compileSdkVersion 30
21+
buildToolsVersion '30.0.3'
2222

2323
compileOptions {
2424
sourceCompatibility JavaVersion.VERSION_1_7
2525
targetCompatibility JavaVersion.VERSION_1_7
2626
}
2727

28+
lintOptions {
29+
abortOnError false
30+
}
31+
2832
defaultConfig {
2933
minSdkVersion 14
30-
targetSdkVersion 27
34+
targetSdkVersion 30
35+
multiDexEnabled true
3136
testApplicationId "com.mixpanel.android.mpmetrics"
32-
testInstrumentationRunner "android.test.InstrumentationTestRunner"
37+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
38+
3339
consumerProguardFiles 'proguard.txt'
3440

3541
buildConfigField "String", "MIXPANEL_VERSION", "\"${version}\""
@@ -41,6 +47,10 @@ android {
4147
textOutput "stdout"
4248
textReport true
4349
}
50+
51+
testOptions {
52+
execution 'ANDROIDX_TEST_ORCHESTRATOR'
53+
}
4454
}
4555
buildTypes {
4656
debug{
@@ -63,7 +73,6 @@ allprojects {
6373
}
6474
repositories {
6575
mavenCentral()
66-
jcenter()
6776
google()
6877
}
6978
}
@@ -73,9 +82,22 @@ allprojects {
7382
// have to change the bit in uploadArchives that marks all dependencies as optional.
7483
dependencies {
7584
api 'com.google.firebase:firebase-messaging:17.3.4'
76-
api 'com.android.installreferrer:installreferrer:1.0'
77-
testImplementation "org.mockito:mockito-core:2.25.1"
85+
implementation("com.google.firebase:firebase-iid")
86+
api 'com.android.installreferrer:installreferrer:2.2'
87+
implementation "androidx.annotation:annotation:1.1.0"
88+
implementation 'androidx.multidex:multidex:2.0.1'
89+
90+
// AndroidJUnitRunner and JUnit Rules
91+
testImplementation 'junit:junit:4.12'
92+
androidTestImplementation 'androidx.test:core:1.4.0'
93+
androidTestImplementation 'androidx.test:runner:1.4.0'
94+
androidTestImplementation 'androidx.test:rules:1.4.0'
95+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
96+
androidTestImplementation 'androidx.test.ext:truth:1.4.0'
7897
androidTestImplementation "org.mockito:mockito-android:2.25.1"
98+
androidTestUtil 'androidx.test:orchestrator:1.4.0'
99+
testImplementation "org.mockito:mockito-core:2.25.1"
100+
79101
}
80102

81103
apply from: rootProject.file('maven.gradle')

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ RELEASE_REPOSITORY_URL=https://oss.sonatype.org/service/local/staging/deploy/mav
1919
SNAPSHOT_REPOSITORY_URL=https://oss.sonatype.org/content/repositories/snapshots/
2020

2121
org.gradle.jvmargs=-Xmx1536M
22+
android.useAndroidX=true
23+
android.enableJetifier=true
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#Thu Sep 30 12:08:33 PDT 2021
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

src/androidTest/java/com/mixpanel/android/mpmetrics/AutomaticEventsTest.java

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import android.os.Handler;
66
import android.os.HandlerThread;
77
import android.os.Process;
8-
import android.test.AndroidTestCase;
8+
9+
import androidx.test.ext.junit.runners.AndroidJUnit4;
10+
import androidx.test.filters.SmallTest;
11+
import androidx.test.platform.app.InstrumentationRegistry;
912

1013
import com.mixpanel.android.util.Base64Coder;
1114
import com.mixpanel.android.util.HttpService;
@@ -14,6 +17,13 @@
1417
import org.json.JSONArray;
1518
import org.json.JSONException;
1619
import org.json.JSONObject;
20+
import org.junit.After;
21+
import org.junit.Before;
22+
import org.junit.Test;
23+
import org.junit.runner.RunWith;
24+
import static org.junit.Assert.assertEquals;
25+
import static org.junit.Assert.assertNull;
26+
import static org.junit.Assert.assertTrue;
1727

1828
import java.io.IOException;
1929
import java.util.Map;
@@ -29,7 +39,9 @@
2939
* Created by sergioalonso on 5/16/17.
3040
*/
3141

32-
public class AutomaticEventsTest extends AndroidTestCase {
42+
@RunWith(AndroidJUnit4.class)
43+
@SmallTest
44+
public class AutomaticEventsTest {
3345

3446
private MixpanelAPI mCleanMixpanelAPI;
3547
private static final String TOKEN = "Automatic Events Token";
@@ -44,10 +56,9 @@ public class AutomaticEventsTest extends AndroidTestCase {
4456
private MPDbAdapter mockAdapter;
4557
private CountDownLatch mMinRequestsLatch;
4658

47-
@Override
48-
protected void setUp() throws Exception {
49-
super.setUp();
50-
mMockReferrerPreferences = new TestUtils.EmptyPreferences(getContext());
59+
@Before
60+
public void setUp() {
61+
mMockReferrerPreferences = new TestUtils.EmptyPreferences(InstrumentationRegistry.getInstrumentation().getContext());
5162
mTrackedEvents = 0;
5263
mCanRunDecide = true;
5364
mMinRequestsLatch = new CountDownLatch(2); // First Time Open and Update
@@ -80,9 +91,9 @@ public byte[] performRequest(String endpointUrl, Map<String, Object> params, SSL
8091
}
8192
};
8293

83-
getContext().deleteDatabase("mixpanel");
94+
InstrumentationRegistry.getInstrumentation().getContext().deleteDatabase("mixpanel");
8495

85-
mockAdapter = new MPDbAdapter(getContext()) {
96+
mockAdapter = new MPDbAdapter(InstrumentationRegistry.getInstrumentation().getContext()) {
8697
@Override
8798
public void cleanupEvents(String last_id, Table table, String token, boolean includeAutomaticEvents) {
8899
if (token.equalsIgnoreCase(TOKEN)) {
@@ -102,7 +113,7 @@ public int addJSON(JSONObject j, String token, Table table, boolean isAutomaticR
102113
}
103114
};
104115

105-
final AnalyticsMessages automaticAnalyticsMessages = new AnalyticsMessages(getContext()) {
116+
final AnalyticsMessages automaticAnalyticsMessages = new AnalyticsMessages(InstrumentationRegistry.getInstrumentation().getContext()) {
106117

107118
@Override
108119
protected RemoteService getPoster() {
@@ -140,7 +151,7 @@ public void runDecideCheck(String token, RemoteService poster) throws RemoteServ
140151
}
141152
};
142153

143-
mCleanMixpanelAPI = new MixpanelAPI(getContext(), mMockReferrerPreferences, TOKEN, false, null) {
154+
mCleanMixpanelAPI = new MixpanelAPI(InstrumentationRegistry.getInstrumentation().getContext(), mMockReferrerPreferences, TOKEN, false, null) {
144155

145156
@Override
146157
/* package */ PersistentIdentity getPersistentIdentity(final Context context, final Future<SharedPreferences> referrerPreferences, final String token) {
@@ -166,12 +177,12 @@ AnalyticsMessages getAnalyticsMessages() {
166177
};
167178
}
168179

169-
@Override
170-
protected void tearDown() throws Exception {
180+
@After
181+
public void tearDown() throws Exception {
171182
mMinRequestsLatch.await(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS);
172-
super.tearDown();
173183
}
174184

185+
@Test
175186
public void testAutomaticOneInstance() throws InterruptedException {
176187
int calls = 3; // First Time Open, App Update, An Event One
177188
mLatch = new CountDownLatch(calls);
@@ -185,6 +196,7 @@ public void testAutomaticOneInstance() throws InterruptedException {
185196
assertEquals(null, mPerformRequestEvents.poll(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
186197
}
187198

199+
@Test
188200
public void testDisableAutomaticEvents() throws InterruptedException {
189201
mCanRunDecide = false;
190202

@@ -211,6 +223,7 @@ public void testDisableAutomaticEvents() throws InterruptedException {
211223
assertEquals(null, mPerformRequestEvents.poll(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
212224
}
213225

226+
@Test
214227
public void testAutomaticMultipleInstances() throws InterruptedException {
215228
final String SECOND_TOKEN = "Automatic Events Token Two";
216229
mCanRunDecide = true;
@@ -243,7 +256,7 @@ public byte[] performRequest(String endpointUrl, Map<String, Object> params, SSL
243256
}
244257
};
245258

246-
final MPDbAdapter mpSecondDbAdapter = new MPDbAdapter(getContext()) {
259+
final MPDbAdapter mpSecondDbAdapter = new MPDbAdapter(InstrumentationRegistry.getInstrumentation().getContext()) {
247260
@Override
248261
public void cleanupEvents(String last_id, Table table, String token, boolean includeAutomaticEvents) {
249262
if (token.equalsIgnoreCase(SECOND_TOKEN)) {
@@ -262,7 +275,7 @@ public int addJSON(JSONObject j, String token, Table table, boolean isAutomaticR
262275
}
263276
};
264277

265-
final AnalyticsMessages mpSecondAnalyticsMessages = new AnalyticsMessages(getContext()) {
278+
final AnalyticsMessages mpSecondAnalyticsMessages = new AnalyticsMessages(InstrumentationRegistry.getInstrumentation().getContext()) {
266279
@Override
267280
protected RemoteService getPoster() {
268281
return mpSecondPoster;
@@ -299,7 +312,7 @@ public void runDecideCheck(String token, RemoteService poster) throws RemoteServ
299312
}
300313
};
301314

302-
MixpanelAPI mpSecondInstance = new TestUtils.CleanMixpanelAPI(getContext(), new TestUtils.EmptyPreferences(getContext()), SECOND_TOKEN) {
315+
MixpanelAPI mpSecondInstance = new TestUtils.CleanMixpanelAPI(InstrumentationRegistry.getInstrumentation().getContext(), new TestUtils.EmptyPreferences(InstrumentationRegistry.getInstrumentation().getContext()), SECOND_TOKEN) {
303316
@Override
304317
AnalyticsMessages getAnalyticsMessages() {
305318
return mpSecondAnalyticsMessages;
@@ -310,15 +323,15 @@ AnalyticsMessages getAnalyticsMessages() {
310323
assertEquals(initialCalls, mTrackedEvents);
311324

312325
assertTrue(secondLatch.await(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
313-
mLatch = new CountDownLatch(MPConfig.getInstance(getContext()).getBulkUploadLimit() - initialCalls);
314-
for (int i = 0; i < MPConfig.getInstance(getContext()).getBulkUploadLimit() - initialCalls; i++) {
326+
mLatch = new CountDownLatch(MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext()).getBulkUploadLimit() - initialCalls);
327+
for (int i = 0; i < MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext()).getBulkUploadLimit() - initialCalls; i++) {
315328
mCleanMixpanelAPI.track("Track event " + i);
316329
}
317330
assertTrue(mLatch.await(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
318331

319332
assertEquals(AutomaticEvents.FIRST_OPEN, mPerformRequestEvents.poll(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
320333
assertEquals(AutomaticEvents.APP_UPDATED, mPerformRequestEvents.poll(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
321-
for (int i = 0; i < MPConfig.getInstance(getContext()).getBulkUploadLimit() - initialCalls; i++) {
334+
for (int i = 0; i < MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext()).getBulkUploadLimit() - initialCalls; i++) {
322335
assertEquals("Track event " + i, mPerformRequestEvents.poll(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
323336
}
324337

0 commit comments

Comments
 (0)