Skip to content

Commit 0e01cac

Browse files
david-allisonBrayanDSO
authored andcommitted
test: ensure org.json is not bundled
Tested on: 4d51a45 - pass c95416c - fail Fixes 20857 Assisted-by: Claude Opus 4.7 - initial test
1 parent 91ad9ef commit 0e01cac

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2026 David Allison <davidallisongithub@gmail.com>
3+
*
4+
* This program is free software; you can redistribute it and/or modify it under
5+
* the terms of the GNU General Public License as published by the Free Software
6+
* Foundation; either version 3 of the License, or (at your option) any later
7+
* version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
10+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11+
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with
14+
* this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
package com.ichi2.anki.tests
18+
19+
import androidx.test.ext.junit.runners.AndroidJUnit4
20+
import androidx.test.platform.app.InstrumentationRegistry
21+
import dalvik.system.DexFile
22+
import org.hamcrest.MatcherAssert.assertThat
23+
import org.hamcrest.Matchers.empty
24+
import org.junit.Test
25+
import org.junit.runner.RunWith
26+
27+
/**
28+
* Regression test for https://github.com/ankidroid/Anki-Android/issues/20852
29+
*/
30+
@RunWith(AndroidJUnit4::class)
31+
class OrgJsonNotBundledTest {
32+
@Test
33+
fun orgJsonIsNotBundledInApk() {
34+
val apkPath =
35+
InstrumentationRegistry
36+
.getInstrumentation()
37+
.targetContext
38+
.applicationInfo
39+
.sourceDir
40+
41+
// DexFile is deprecated since API 26 but still functional
42+
// Reflection on BaseDexClassLoader.pathList is possible, but requires multiple lint
43+
// suppressions on private APIs.
44+
// We could pin this code to work on an earlier emulator if/when it's removed
45+
@Suppress("DEPRECATION")
46+
val orgJsonClasses =
47+
DexFile(apkPath)
48+
.entries()
49+
.toList()
50+
.filter { it.startsWith("org.json.") }
51+
52+
assertThat(
53+
"`org.json` must come from android.jar, not be bundled in the APK. " +
54+
"Use `compileOnly(libs.json)` rather than `implementation(libs.json)`.",
55+
orgJsonClasses,
56+
empty(),
57+
)
58+
}
59+
}

0 commit comments

Comments
 (0)