Skip to content

Commit dde6939

Browse files
Update to AGP-8 and Android-15 (API 35+)
1 parent a71db0d commit dde6939

31 files changed

Lines changed: 433 additions & 304 deletions

Paintroid/build.gradle

Lines changed: 84 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,33 @@
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
1919

20-
apply plugin: 'com.android.library'
21-
apply plugin: 'com.hiya.jacoco-android'
22-
apply plugin: 'com.getkeepsafe.dexcount'
23-
apply plugin: 'kotlin-android'
24-
apply plugin: 'org.catrobat.gradle.androidemulators'
25-
apply plugin: 'maven-publish'
20+
plugins {
21+
id "com.android.library"
22+
id "jacoco"
23+
id "com.getkeepsafe.dexcount"
24+
id "org.jetbrains.kotlin.android"
25+
id "org.catrobat.gradle.androidemulators"
26+
id "maven-publish"
27+
}
2628

27-
apply from: 'gradle/adb_tasks.gradle'
28-
apply from: 'gradle/code_quality_tasks.gradle'
29+
apply from: "gradle/adb_tasks.gradle"
30+
apply from: "gradle/code_quality_tasks.gradle"
2931

3032
emulators {
31-
install project.hasProperty('installSdk')
32-
33-
dependencies {
34-
sdk()
35-
}
33+
install project.hasProperty("installSdk")
34+
dependencies { sdk() }
3635

37-
emulator 'android28', {
36+
emulator "android28", {
3837
avd {
39-
systemImage = 'system-images;android-28;default;x86_64'
38+
systemImage = "system-images;android-28;default;x86_64"
4039
sdcardSizeMb = 1024
41-
hardwareProperties += ['hw.ramSize': 4096, 'vm.heapSize': 1024]
42-
screenDensity = 'xhdpi'
40+
hardwareProperties += ["hw.ramSize": 4096, "vm.heapSize": 1024]
41+
screenDensity = "xhdpi"
4342
}
44-
4543
parameters {
46-
resolution = '768x1280'
47-
language = 'en'
48-
country = 'US'
44+
resolution = "768x1280"
45+
language = "en"
46+
country = "US"
4947
}
5048
}
5149
}
@@ -54,54 +52,50 @@ jacoco {
5452
toolVersion = "0.8.7"
5553
}
5654

57-
jacocoAndroidUnitTestReport {
58-
csv.enabled false
59-
html.enabled true
60-
xml.enabled true
61-
destination project.getBuildDir().getPath() + "/reports/jacoco/jacocoTestDebugUnitTestReport"
62-
}
63-
6455
android {
65-
compileSdkVersion rootProject.ext.androidCompileSdkVersion
56+
namespace "org.catrobat.paintroid"
57+
58+
// New AGP DSL
59+
compileSdk = rootProject.ext.androidCompileSdkVersion
6660

6761
defaultConfig {
68-
minSdkVersion rootProject.ext.androidMinSdkVersion
69-
targetSdkVersion rootProject.ext.androidTargetSdkVersion
70-
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
71-
versionCode rootProject.ext.androidVersionCode
72-
versionName rootProject.ext.androidVersionName
62+
minSdk = rootProject.ext.androidMinSdkVersion
63+
targetSdk = rootProject.ext.androidTargetSdkVersion
64+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
65+
}
66+
67+
buildFeatures {
68+
buildConfig = true
7369
}
7470

7571
compileOptions {
76-
sourceCompatibility JavaVersion.VERSION_11
77-
targetCompatibility JavaVersion.VERSION_11
72+
sourceCompatibility = JavaVersion.VERSION_17
73+
targetCompatibility = JavaVersion.VERSION_17
7874
}
75+
kotlinOptions { jvmTarget = "17" }
7976

8077
buildTypes {
8178
release {
82-
minifyEnabled false
83-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
84-
}
85-
signedRelease {
79+
minifyEnabled = false
80+
proguardFiles(
81+
getDefaultProguardFile("proguard-android.txt"),
82+
"proguard-rules.pro"
83+
)
8684
}
85+
create("signedRelease")
8786
debug {
88-
testCoverageEnabled = project.hasProperty('enableCoverage')
89-
// Multidex is required as espresso and mockito/bytebuddy are adding more functions
90-
// than should be allowed by law.
91-
// See https://github.com/mockito/mockito/issues/1112
92-
multiDexEnabled true
9387
}
9488
}
9589

96-
lintOptions {
97-
// specific ignores should be defined via lint.xml file
98-
lintConfig file('config/lint.xml')
99-
ignore 'ClickableViewAccessibility', 'StaticFieldLeak', 'GradleDependency', 'OldTargetApi', 'LintBaseline'
100-
textReport true
101-
xmlReport true
102-
htmlReport true
103-
xmlOutput file("build/reports/lint-report.xml")
104-
htmlOutput file("build/reports/lint-report.html")
90+
lint {
91+
lintConfig file("config/lint.xml")
92+
disable "ClickableViewAccessibility", "StaticFieldLeak",
93+
"GradleDependency", "OldTargetApi", "LintBaseline"
94+
textReport = true
95+
xmlReport = true
96+
htmlReport = true
97+
xmlOutput = file("build/reports/lint-report.xml")
98+
htmlOutput = file("build/reports/lint-report.html")
10599
}
106100

107101
testOptions {
@@ -111,54 +105,51 @@ android {
111105

112106
packagingOptions {
113107
resources {
114-
excludes += ['META-INF/AL2.0', 'META-INF/LGPL2.1', "**/attach_hotspot_windows.dll"]
115-
merges += ['META-INF/licenses/ASM']
108+
excludes += ["META-INF/AL2.0", "META-INF/LGPL2.1", "**/attach_hotspot_windows.dll"]
109+
merges += ["META-INF/licenses/ASM"]
116110
}
117111
}
118112
}
119113

120114
dependencies {
121-
implementation 'androidx.appcompat:appcompat:1.0.0'
122-
implementation 'com.google.android.material:material:1.2.1'
123-
implementation project(':colorpicker')
115+
implementation "androidx.appcompat:appcompat:1.0.0"
116+
implementation "com.google.android.material:material:1.2.1"
117+
implementation project(":colorpicker")
124118

125-
implementation 'androidx.core:core-ktx:1.3.2'
119+
implementation "androidx.core:core-ktx:1.3.2"
126120
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
127-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8'
128-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8'
129-
implementation 'androidx.exifinterface:exifinterface:1.3.2'
130-
implementation 'com.esotericsoftware:kryo:5.5.0'
131-
implementation 'id.zelory:compressor:2.1.1'
132-
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
133-
134-
debugImplementation 'androidx.multidex:multidex:2.0.0'
135-
136-
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
137-
implementation 'com.jraska:falcon:2.2.0'
138-
139-
testImplementation 'junit:junit:4.12'
140-
testImplementation 'org.mockito:mockito-core:2.18.3'
141-
testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'
142-
143-
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.4.3'
144-
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
145-
androidTestImplementation 'androidx.test:rules:1.1.1'
146-
androidTestImplementation 'org.mockito:mockito-android:3.6.28'
147-
androidTestImplementation 'tools.fastlane:screengrab:2.1.0'
148-
androidTestImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'
149-
150-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
151-
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0'
152-
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
121+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8"
122+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8"
123+
implementation "androidx.exifinterface:exifinterface:1.3.2"
124+
implementation "com.esotericsoftware:kryo:5.5.0"
125+
implementation "id.zelory:compressor:2.1.1"
126+
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
127+
implementation 'androidx.test:monitor:1.8.0'
128+
129+
debugImplementation "androidx.multidex:multidex:2.0.0"
130+
131+
implementation "com.nostra13.universalimageloader:universal-image-loader:1.9.5"
132+
implementation "com.jraska:falcon:2.2.0"
133+
134+
testImplementation "junit:junit:4.12"
135+
testImplementation "org.mockito:mockito-core:2.18.3"
136+
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
137+
138+
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.4.3"
139+
androidTestImplementation "androidx.test.ext:junit:1.1.3"
140+
androidTestImplementation "androidx.test:rules:1.1.1"
141+
androidTestImplementation "org.mockito:mockito-android:3.6.28"
142+
androidTestImplementation "tools.fastlane:screengrab:2.1.0"
143+
androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
144+
145+
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
146+
androidTestImplementation "androidx.test.espresso:espresso-contrib:3.1.0"
147+
androidTestImplementation "androidx.test.espresso:espresso-intents:3.1.0"
153148
androidTestImplementation "androidx.test.uiautomator:uiautomator:2.2.0"
154149
testImplementation "androidx.test:core-ktx:1.4.0"
155-
implementation 'com.android.support.test.espresso:espresso-idling-resource:3.1.0'
156-
}
157150

158-
tasks.withType(Javadoc).all {
159-
enabled = false
151+
implementation "androidx.test.espresso:espresso-idling-resource:3.5.1"
160152
}
161153

162-
if (project.hasProperty('jenkins')) {
163-
android.dexOptions.preDexLibraries = false
164-
}
154+
tasks.withType(Javadoc).configureEach { enabled = false }
155+

Paintroid/gradle/code_quality_tasks.gradle

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,30 @@ task checkstyle(type: Checkstyle) {
4242

4343
classpath = files()
4444

45-
// needed for console output of warnings/errors
46-
showViolations true
47-
ignoreFailures false
45+
// console printing is automatic; use ignoreFailures to fail or not
46+
ignoreFailures = false
4847

4948
reports {
50-
xml.enabled = true
51-
xml.destination file("build/reports/checkstyle.xml")
49+
xml.required.set(true)
50+
html.required.set(false)
51+
xml.outputLocation.set(file("$buildDir/reports/checkstyle.xml"))
5252
}
5353
}
5454

5555
task pmd(type: Pmd) {
5656
ruleSetFiles = files('config/pmd.xml')
57-
ruleSets = []
57+
ruleSets = [] // don't use built-in default sets
5858

5959
source '.'
6060
include '**/*.java'
6161
exclude '**/gen/**', '**/build/**', '**/res/**'
6262

63-
ignoreFailures false
63+
ignoreFailures = false
6464

6565
reports {
66-
xml.enabled = true
67-
html.enabled = true
68-
xml.destination file("build/reports/pmd.xml")
66+
xml.required.set(true)
67+
html.required.set(true)
68+
xml.outputLocation.set(file("$buildDir/reports/pmd.xml"))
6969
}
7070
}
7171

Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/CatrobatImageIOIntegrationTest.kt

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
package org.catrobat.paintroid.test.espresso
2222

23+
import android.Manifest
2324
import android.net.Uri
25+
import android.os.Build
2426
import android.os.Environment
2527
import androidx.test.espresso.Espresso
2628
import androidx.test.espresso.Espresso.onView
@@ -32,15 +34,14 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
3234
import androidx.test.espresso.matcher.ViewMatchers.withId
3335
import androidx.test.espresso.matcher.ViewMatchers.withText
3436
import androidx.test.ext.junit.runners.AndroidJUnit4
37+
import androidx.test.platform.app.InstrumentationRegistry
3538
import androidx.test.rule.ActivityTestRule
36-
import androidx.test.rule.GrantPermissionRule
3739
import org.catrobat.paintroid.FileIO
3840
import org.catrobat.paintroid.MainActivity
3941
import org.catrobat.paintroid.command.serialization.CommandSerializer
4042
import org.catrobat.paintroid.R
4143
import org.catrobat.paintroid.common.CATROBAT_IMAGE_ENDING
4244
import org.catrobat.paintroid.test.espresso.util.DrawingSurfaceLocationProvider
43-
import org.catrobat.paintroid.test.espresso.util.EspressoUtils
4445
import org.catrobat.paintroid.test.espresso.util.UiInteractions
4546
import org.catrobat.paintroid.test.espresso.util.wrappers.DrawingSurfaceInteraction.Companion.onDrawingSurfaceView
4647
import org.catrobat.paintroid.test.espresso.util.wrappers.TopBarViewInteraction
@@ -52,21 +53,20 @@ import org.junit.Assert
5253
import org.junit.Before
5354
import org.junit.Rule
5455
import org.junit.Test
56+
import org.junit.rules.RuleChain
5557
import org.junit.runner.RunWith
5658
import java.io.File
5759

5860
@RunWith(AndroidJUnit4::class)
5961
class CatrobatImageIOIntegrationTest {
6062

6163
@get:Rule
62-
val launchActivityRule = ActivityTestRule(MainActivity::class.java)
64+
val launchActivityRule =
65+
ActivityTestRule(MainActivity::class.java, true, false)
6366

6467
@get:Rule
6568
val screenshotOnFailRule = ScreenshotOnFailRule()
6669

67-
@get:Rule
68-
val grantPermissionRule: GrantPermissionRule = EspressoUtils.grantPermissionRulesVersionCheck()
69-
7070
private var uriFile: Uri? = null
7171
private lateinit var activity: MainActivity
7272

@@ -75,12 +75,38 @@ class CatrobatImageIOIntegrationTest {
7575
}
7676

7777
@Before
78-
fun setUp() { activity = launchActivityRule.activity }
78+
fun setUp() {
79+
val inst = InstrumentationRegistry.getInstrumentation()
80+
val targetPkg = inst.targetContext.packageName
81+
val perms = when {
82+
Build.VERSION.SDK_INT >= 34 -> arrayOf(
83+
Manifest.permission.READ_MEDIA_IMAGES,
84+
Manifest.permission.READ_MEDIA_VIDEO,
85+
"android.permission.READ_MEDIA_VISUAL_USER_SELECTED"
86+
)
87+
Build.VERSION.SDK_INT >= 33 -> arrayOf(
88+
Manifest.permission.READ_MEDIA_IMAGES,
89+
Manifest.permission.READ_MEDIA_VIDEO
90+
)
91+
else -> arrayOf(
92+
Manifest.permission.READ_EXTERNAL_STORAGE
93+
)
94+
}
95+
perms.forEach {
96+
try {
97+
inst.uiAutomation.grantRuntimePermission(targetPkg, it)
98+
} catch (_: Exception) {
99+
}
100+
}
101+
102+
launchActivityRule.launchActivity(null)
103+
activity = launchActivityRule.activity
104+
}
79105

80106
@After
81107
fun tearDown() {
82108
val imagesDirectory =
83-
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString()
109+
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString()
84110
val pathToFile = imagesDirectory + File.separator + IMAGE_NAME + "." + CATROBAT_IMAGE_ENDING
85111
val imageFile = File(pathToFile)
86112
if (imageFile.exists()) {

0 commit comments

Comments
 (0)