Skip to content

Commit aa7977c

Browse files
committed
run aapt for library
1 parent 13bdefb commit aa7977c

File tree

9 files changed

+154
-50
lines changed

9 files changed

+154
-50
lines changed

app/src/main/java/com/duy/projectview/view/fragments/FolderStructureFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public TreeNode refresh() {
253253
}
254254

255255
mTreeView = new AndroidTreeView(getContext(), root);
256-
mTreeView.setDefaultAnimation(true);
256+
mTreeView.setDefaultAnimation(false);
257257
mTreeView.setDefaultContainerStyle(R.style.TreeNodeStyleCustom);
258258
mTreeView.setDefaultViewHolder(FolderHolder.class);
259259
mTreeView.setDefaultNodeClickListener(nodeClickListener);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>android.arch.lifecycle</groupId>
6+
<artifactId>common</artifactId>
7+
<version>1.1.0</version>
8+
<name>Android Lifecycle-Common</name>
9+
<description>Android Lifecycle-Common</description>
10+
<url>https://developer.android.com/topic/libraries/architecture/index.html</url>
11+
<inceptionYear>2017</inceptionYear>
12+
<licenses>
13+
<license>
14+
<name>The Apache Software License, Version 2.0</name>
15+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
16+
<distribution>repo</distribution>
17+
</license>
18+
</licenses>
19+
<developers>
20+
<developer>
21+
<name>The Android Open Source Project</name>
22+
</developer>
23+
</developers>
24+
<scm>
25+
<connection>scm:git:https://android.googlesource.com/platform/frameworks/support</connection>
26+
<url>http://source.android.com</url>
27+
</scm>
28+
<dependencies>
29+
<dependency>
30+
<groupId>com.android.support</groupId>
31+
<artifactId>support-annotations</artifactId>
32+
<version>26.1.0</version>
33+
<scope>compile</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>junit</groupId>
37+
<artifactId>junit</artifactId>
38+
<version>4.12</version>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.mockito</groupId>
43+
<artifactId>mockito-core</artifactId>
44+
<version>2.7.6</version>
45+
<scope>test</scope>
46+
</dependency>
47+
</dependencies>
48+
</project>
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,50 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4-
<modelVersion>4.0.0</modelVersion>
5-
<groupId>com.android.support</groupId>
6-
<artifactId>support-core-utils</artifactId>
7-
<version>27.1.1</version>
8-
<packaging>aar</packaging>
9-
<name>Android Support Library core utils</name>
10-
<description>The Support Library is a static library that you can add to your Android application in order to use APIs that are either not available for older platform versions or utility APIs that aren't a part of the framework APIs. Compatible on devices running API 14 or later.</description>
11-
<url>http://developer.android.com/tools/extras/support-library.html</url>
12-
<inceptionYear>2011</inceptionYear>
13-
<licenses>
14-
<license>
15-
<name>The Apache Software License, Version 2.0</name>
16-
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
17-
<distribution>repo</distribution>
18-
</license>
19-
</licenses>
20-
<developers>
21-
<developer>
22-
<name>The Android Open Source Project</name>
23-
</developer>
24-
</developers>
25-
<scm>
26-
<connection>scm:git:https://android.googlesource.com/platform/frameworks/support</connection>
27-
<url>http://source.android.com</url>
28-
</scm>
29-
<dependencies>
30-
<dependency>
31-
<groupId>com.android.support</groupId>
32-
<artifactId>support-annotations</artifactId>
33-
<version>27.1.1</version>
34-
<scope>compile</scope>
35-
</dependency>
36-
<dependency>
37-
<groupId>com.android.support</groupId>
38-
<artifactId>support-compat</artifactId>
39-
<version>27.1.1</version>
40-
<type>aar</type>
41-
<scope>compile</scope>
42-
</dependency>
43-
</dependencies>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>com.android.support</groupId>
7+
<artifactId>support-core-utils</artifactId>
8+
<version>27.1.1</version>
9+
<packaging>aar</packaging>
10+
<name>Android Support Library core utils</name>
11+
<description>The Support Library is a static library that you can add to your Android
12+
application in order to use APIs that are either not available for older platform versions
13+
or utility APIs that aren't a part of the framework APIs. Compatible on devices running API
14+
14 or later.
15+
</description>
16+
<url>http://developer.android.com/tools/extras/support-library.html</url>
17+
<inceptionYear>2011</inceptionYear>
18+
<licenses>
19+
<license>
20+
<name>The Apache Software License, Version 2.0</name>
21+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
22+
<distribution>repo</distribution>
23+
</license>
24+
</licenses>
25+
<developers>
26+
<developer>
27+
<name>The Android Open Source Project</name>
28+
</developer>
29+
</developers>
30+
<scm>
31+
<connection>scm:git:https://android.googlesource.com/platform/frameworks/support
32+
</connection>
33+
<url>http://source.android.com</url>
34+
</scm>
35+
<dependencies>
36+
<dependency>
37+
<groupId>com.android.support</groupId>
38+
<artifactId>support-annotations</artifactId>
39+
<version>27.1.1</version>
40+
<scope>compile</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>com.android.support</groupId>
44+
<artifactId>support-compat</artifactId>
45+
<version>27.1.1</version>
46+
<type>aar</type>
47+
<scope>compile</scope>
48+
</dependency>
49+
</dependencies>
4450
</project>

lib-android-compiler/src/main/assets/libs/27.1.1/support-fragment-27.1.1.pom

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.android.support</groupId>
77
<artifactId>support-fragment</artifactId>

lib-android-compiler/src/main/java/com/duy/android/compiler/builder/task/android/Aapt.java

+33
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,35 @@ public boolean run() throws IOException, InterruptedException {
151151
}
152152
File aaptFile = new File(Environment.getBinDir(context), aaptName);
153153

154+
if (project.getDependencies().size() > 0) {
155+
builder.stdout("Run AAPT for all libraries");
156+
//run aapt for library
157+
for (AndroidLibraryProject library : project.getDependencies()) {
158+
builder.stdout("AAPT for library " + library.getProjectName());
159+
Argument args = new Argument();
160+
args.add(aaptFile.getAbsolutePath());
161+
args.add("p"); //package
162+
args.add("-f"); //force overwrite of existing files
163+
args.add("--auto-add-overlay");
164+
if (builder.isVerbose()) {
165+
args.add("-v"); //debug
166+
}
167+
args.add("--non-constant-id"); //non constant for library
168+
args.add("-M", library.getXmlManifest().getAbsolutePath()); //manifest file
169+
args.add("-A", library.getAssetsDir().getAbsolutePath()); //input assets dir
170+
args.add("-I", project.getBootClassPath(context));//The location of the android.jar resource
171+
args.add("-S", library.getResDir().getAbsolutePath()); //input resource dir
172+
args.add("-m"); // make package directories under location specified by -J
173+
//specify where to output R.java resource constant definitions
174+
args.add("-J", library.getDirGeneratedSource().getAbsolutePath());
175+
176+
boolean complete = execAapt(aaptFile, args);
177+
if (!complete) {
178+
return false;
179+
}
180+
}
181+
}
182+
154183
Argument args = new Argument();
155184
args.add(aaptFile.getAbsolutePath());
156185
args.add("p", "-f", "--auto-add-overlay");
@@ -166,6 +195,10 @@ public boolean run() throws IOException, InterruptedException {
166195
args.add("-S", library.getResDir().getAbsolutePath());
167196
args.add("-A", library.getAssetsDir().getAbsolutePath()); //input assets dir
168197
}
198+
return execAapt(aaptFile, args);
199+
}
200+
201+
private boolean execAapt(File aaptFile, Argument args) throws InterruptedException, IOException {
169202
final int[] exitCode = new int[1];
170203
final Process aaptProcess = Runtime.getRuntime().exec(args.toArray());
171204
Thread thread = new Thread(new Runnable() {

lib-android-compiler/src/main/java/com/duy/android/compiler/project/AndroidProjectManager.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public AndroidApplicationProject createNewProject(Context context, File dir, Str
4848
createManifest(project, activityClass, packageName, assets);
4949
createMainActivity(project, activityClass, packageName, activityName, appName, useCompatLibrary, assets);
5050
createMainLayoutXml(project, mainLayoutName);
51-
copyLibrary(project, useCompatLibrary, assets);
51+
copyLibrary(project, useCompatLibrary);
5252

5353
return project;
5454
}
@@ -125,11 +125,13 @@ private void saveFile(File file, String content) throws IOException {
125125
output.close();
126126
}
127127

128-
private void copyLibrary(AndroidApplicationProject project, boolean useCompatLibrary, AssetManager assets) throws IOException, StreamException, SAXException, ParserConfigurationException {
128+
private void copyLibrary(AndroidApplicationProject project, boolean useCompatLibrary)
129+
throws IOException, StreamException, SAXException, ParserConfigurationException {
129130
if (useCompatLibrary) {
130131
//v7
131132
addLib(project, "libs/27.1.1/android.arch.core-common-1.1.0.jar", "android.arch.core-common-1.1.0.jar");
132133
addLib(project, "libs/27.1.1/android.arch.core-runtime-1.1.0.aar", "android.arch.core-runtime-1.1.0");
134+
addLib(project, "libs/27.1.1/android.arch.lifecycle-common-1.1.0.jar", "android.arch.lifecycle-common-1.1.0.jar");
133135
addLib(project, "libs/27.1.1/android.arch.lifecycle-livedata-core-1.1.0.aar", "android.arch.lifecycle-livedata-core-1.1.0");
134136
addLib(project, "libs/27.1.1/android.arch.lifecycle-runtime-1.1.0.aar", "android.arch.lifecycle-runtime-1.1.0");
135137
addLib(project, "libs/27.1.1/android.arch.lifecycle-viewmodel-1.1.0.aar", "android.arch.lifecycle-viewmodel-1.1.0");
@@ -155,12 +157,10 @@ private void addLib(AndroidApplicationProject project, String assetsPath, String
155157
output.close();
156158
} else if (assetsPath.endsWith(".aar")) {
157159
File aarFile = new File(project.getDirBuildDexedLibs(), assetsPath);
158-
// if (!aarFile.exists()) {
159160
aarFile.getParentFile().mkdirs();
160161
FileOutputStream output = new FileOutputStream(aarFile);
161162
IOUtils.copy(context.getAssets().open(assetsPath), output);
162163
output.close();
163-
// }
164164

165165
AndroidLibraryExtractor extractor = new AndroidLibraryExtractor(context);
166166
extractor.extract(aarFile, libName);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.duy.android.compiler.project;
2+
3+
import java.io.File;
4+
5+
public class JavaLibraryProject extends JavaProject {
6+
public JavaLibraryProject(File rootFile) {
7+
super(rootFile, "", "");
8+
}
9+
10+
public JavaLibraryProject(File root, String mainClassName, String packageName) {
11+
super(root, mainClassName, packageName);
12+
}
13+
}

lib-android-compiler/src/main/java/com/duy/android/compiler/project/JavaProject.java

+4
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,8 @@ public ArrayList<File> getJavaSrcDirs() {
346346
public File getJavaSrcDir() {
347347
return javaSrcDirs.get(0);
348348
}
349+
350+
public File getDirGeneratedSource() {
351+
return dirGeneratedSource;
352+
}
349353
}

0 commit comments

Comments
 (0)