Skip to content

Commit f078148

Browse files
authored
Merge pull request androidannotations#2065 from dodgex/2034_update_manifest_finder_to_support_splits
Update Manifest finder for apk splits
2 parents 177b023 + d4eee5d commit f078148

2 files changed

Lines changed: 47 additions & 4 deletions

File tree

AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/helper/AndroidManifestFinder.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ private static class GradleAndroidManifestFinderStrategy extends AndroidManifest
181181

182182
static final Pattern GRADLE_GEN_FOLDER = Pattern.compile("^(.*?)build[\\\\/]generated[\\\\/]source[\\\\/](k?apt)(.*)$");
183183

184+
private static final List<String> SUPPORTED_ABI_SPLITS = Arrays.asList("arm64-v8a", "armeabi", "armeabi-v7a", "mips", "mips64", "x86", "x86_64");
185+
private static final List<String> SUPPORTED_DENSITY_SPLITS = Arrays.asList("hdpi", "ldpi", "mdpi", "xhdpi", "xxhdpi", "xxxhdpi");
186+
184187
GradleAndroidManifestFinderStrategy(String sourceFolder) {
185188
super("Gradle", GRADLE_GEN_FOLDER, sourceFolder);
186189
}
@@ -192,10 +195,6 @@ Iterable<String> possibleLocations() {
192195
String gradleVariant = matcher.group(3);
193196
String variantPart = gradleVariant.substring(1);
194197

195-
if ("apt".equals(mode)) {
196-
return Arrays.asList("build/intermediates/manifests/full" + gradleVariant, "build/intermediates/bundles" + gradleVariant, "build/intermediates/manifests/aapt" + gradleVariant);
197-
}
198-
199198
ArrayList<String> possibleLocations = new ArrayList<>();
200199

201200
for (String directory : Arrays.asList("build/intermediates/manifests/full", "build/intermediates/bundles", "build/intermediates/manifests/aapt")) {
@@ -212,19 +211,45 @@ private void findPossibleLocations(String basePath, String targetPath, String va
212211
return;
213212
}
214213

214+
if (variantPart.startsWith("/") || variantPart.startsWith("\\")) {
215+
variantPart = variantPart.substring(1);
216+
}
217+
215218
for (String directory : directories) {
216219
String possibleLocation = targetPath + "/" + directory;
217220
File variantDir = new File(basePath + possibleLocation);
218221
if (variantDir.isDirectory() && variantPart.toLowerCase().startsWith(directory.toLowerCase())) {
219222
String remainingPart = variantPart.substring(directory.length());
220223
if (remainingPart.length() == 0) {
221224
possibleLocations.add(possibleLocation);
225+
addPossibleSplitLocations(basePath, possibleLocation, possibleLocations);
222226
} else {
223227
findPossibleLocations(basePath, possibleLocation, remainingPart, possibleLocations);
224228
}
225229
}
226230
}
227231
}
232+
233+
private void addPossibleSplitLocations(String basePath, String possibleLocation, List<String> possibleLocations) {
234+
for (String abiSplit : SUPPORTED_ABI_SPLITS) {
235+
File splitDir = new File(basePath + possibleLocation + "/" + abiSplit);
236+
if (splitDir.isDirectory()) {
237+
possibleLocations.add(possibleLocation + "/" + abiSplit);
238+
for (String densitySplit : SUPPORTED_DENSITY_SPLITS) {
239+
File splitSubDir = new File(basePath + possibleLocation + "/" + abiSplit + "/" + densitySplit);
240+
if (splitSubDir.isDirectory()) {
241+
possibleLocations.add(possibleLocation + "/" + abiSplit + "/" + densitySplit);
242+
}
243+
}
244+
}
245+
}
246+
for (String densitySplit : SUPPORTED_DENSITY_SPLITS) {
247+
File splitDir = new File(basePath + possibleLocation + "/" + densitySplit);
248+
if (splitDir.isDirectory()) {
249+
possibleLocations.add(possibleLocation + "/" + densitySplit);
250+
}
251+
}
252+
}
228253
}
229254

230255
private static class MavenAndroidManifestFinderStrategy extends AndroidManifestFinderStrategy {

AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/internal/helper/AndroidManifestFinderTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,25 @@ public static Iterable<Object[]> createTestData() {
6363
Object[] gradleManifestFoundInManifestsWithFlavor = { GRADLE_FLAVOR_GEN_FOLDER, "build/intermediates/manifests/full/flavor/debug", true };
6464
Object[] gradleManifestFoundInBundlesWithFlavor = { GRADLE_FLAVOR_GEN_FOLDER, "build/intermediates/bundles/flavor/debug", true };
6565
Object[] gradleManifestFoundInManifestsAaptWithFlavor = { GRADLE_FLAVOR_GEN_FOLDER, "build/intermediates/manifests/aapt/flavor/debug", true };
66+
Object[] gradleManifestFoundInManifestsWithAbiSplit = { GRADLE_GEN_FOLDER, "build/intermediates/manifests/full/debug/x86", true };
67+
Object[] gradleManifestFoundInManifestsWithAbiSplitAndFlavor = { GRADLE_FLAVOR_GEN_FOLDER, "build/intermediates/manifests/full/flavor/debug/x86", true };
68+
Object[] gradleManifestFoundInManifestsWithDensitySplit = { GRADLE_GEN_FOLDER, "build/intermediates/manifests/full/debug/hdpi", true };
69+
Object[] gradleManifestFoundInManifestsWithDensitySplitAndFlavor = { GRADLE_FLAVOR_GEN_FOLDER, "build/intermediates/manifests/full/flavor/debug/hdpi", true };
70+
Object[] gradleManifestFoundInManifestsWithBothSplit = { GRADLE_GEN_FOLDER, "build/intermediates/manifests/full/debug/x86/hdpi", true };
71+
Object[] gradleManifestFoundInManifestsWithBothSplitAndFlavor = { GRADLE_FLAVOR_GEN_FOLDER, "build/intermediates/manifests/full/flavor/debug/x86/hdpi", true };
6672

6773
Object[] gradleKotlinManifestFoundInManifests = { GRADLE_KOTLIN_GEN_FOLDER, "build/intermediates/manifests/full/debug", true };
6874
Object[] gradleKotlinManifestFoundInBundles = { GRADLE_KOTLIN_GEN_FOLDER, "build/intermediates/bundles/debug", true };
6975
Object[] gradleKotlinManifestFoundInManifestsAapt = { GRADLE_KOTLIN_GEN_FOLDER, "build/intermediates/manifests/aapt/debug", true };
7076
Object[] gradleKotlinManifestFoundInManifestsWithFlavor = { GRADLE_KOTLIN_FLAVOR_GEN_FOLDER, "build/intermediates/manifests/full/flavor/debug", true };
7177
Object[] gradleKotlinManifestFoundInBundlesWithFlavor = { GRADLE_KOTLIN_FLAVOR_GEN_FOLDER, "build/intermediates/bundles/flavor/debug", true };
7278
Object[] gradleKotlinManifestFoundInManifestsAaptWithFlavor = { GRADLE_KOTLIN_FLAVOR_GEN_FOLDER, "build/intermediates/manifests/aapt/flavor/debug", true };
79+
Object[] gradleKotlinManifestFoundInManifestsWithAbiSplit = { GRADLE_KOTLIN_GEN_FOLDER, "build/intermediates/manifests/full/debug/x86", true };
80+
Object[] gradleKotlinManifestFoundInManifestsWithAbiSplitAndFlavor = { GRADLE_KOTLIN_FLAVOR_GEN_FOLDER, "build/intermediates/manifests/full/flavor/debug/x86", true };
81+
Object[] gradleKotlinManifestFoundInManifestsWithDensitySplit = { GRADLE_KOTLIN_GEN_FOLDER, "build/intermediates/manifests/full/debug/hdpi", true };
82+
Object[] gradleKotlinManifestFoundInManifestsWithDensitySplitAndFlavor = { GRADLE_KOTLIN_FLAVOR_GEN_FOLDER, "build/intermediates/manifests/full/flavor/debug/hdpi", true };
83+
Object[] gradleKotlinManifestFoundInManifestsWithBothSplit = { GRADLE_KOTLIN_GEN_FOLDER, "build/intermediates/manifests/full/debug/x86/hdpi", true };
84+
Object[] gradleKotlinManifestFoundInManifestsWithBothSplitAndFlavor = { GRADLE_KOTLIN_FLAVOR_GEN_FOLDER, "build/intermediates/manifests/full/flavor/debug/x86/hdpi", true };
7385

7486
Object[] mavenManifestFoundInTarget = { MAVEN_GEN_FOLDER, "target", true };
7587
Object[] mavenManifestFoundInSrc = { MAVEN_GEN_FOLDER, "src/main", true };
@@ -89,8 +101,14 @@ public static Iterable<Object[]> createTestData() {
89101

90102
return Arrays.asList(gradleManifestFoundInManifests, gradleManifestFoundInBundles, gradleManifestFoundInManifestsAapt,
91103
gradleManifestFoundInManifestsWithFlavor, gradleManifestFoundInBundlesWithFlavor, gradleManifestFoundInManifestsAaptWithFlavor,
104+
gradleManifestFoundInManifestsWithAbiSplit, gradleManifestFoundInManifestsWithAbiSplitAndFlavor,
105+
gradleManifestFoundInManifestsWithDensitySplit, gradleManifestFoundInManifestsWithDensitySplitAndFlavor,
106+
gradleManifestFoundInManifestsWithBothSplit, gradleManifestFoundInManifestsWithBothSplitAndFlavor,
92107
gradleKotlinManifestFoundInManifests, gradleKotlinManifestFoundInBundles, gradleKotlinManifestFoundInManifestsAapt,
93108
gradleKotlinManifestFoundInManifestsWithFlavor, gradleKotlinManifestFoundInBundlesWithFlavor, gradleKotlinManifestFoundInManifestsAaptWithFlavor,
109+
gradleKotlinManifestFoundInManifestsWithAbiSplit, gradleKotlinManifestFoundInManifestsWithAbiSplitAndFlavor,
110+
gradleKotlinManifestFoundInManifestsWithDensitySplit, gradleKotlinManifestFoundInManifestsWithDensitySplitAndFlavor,
111+
gradleKotlinManifestFoundInManifestsWithBothSplit, gradleKotlinManifestFoundInManifestsWithBothSplitAndFlavor,
94112
mavenManifestFoundInTarget, mavenManifestFoundInSrc, mavenManifestFoundInRoot, eclipseManifestFound,
95113
gradleManifestNotFound, gradleKotlinManifestNotFound, mavenManifestNotFound, eclipseManifestNotFound,
96114
noGeneratedFolderFound);

0 commit comments

Comments
 (0)