Skip to content

Commit

Permalink
- Maven build now produces a functioning app
Browse files Browse the repository at this point in the history
- Added non-mavenized dependencies (dexj2ar and apktool) to a local maven repo to take advantage of Maven's assembly plugin
- Fixed issue when no device is connected.
  • Loading branch information
Dan Watling committed Jan 3, 2016
1 parent 61fe99e commit 8ad9b87
Show file tree
Hide file tree
Showing 29 changed files with 243 additions and 21 deletions.
89 changes: 77 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,28 @@
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
</properties>

<repositories>
<repository>
<id>apkdecompiler</id>
<url>file://${project.basedir}/repo</url>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -23,19 +43,29 @@
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.danwatling.apkdecompiler.Main</mainClass>
</manifest>
<manifestEntries>
<Class-Path>lib/</Class-Path>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<id>create-my-bundle</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>${project.artifactId}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>com.danwatling.apkdecompiler.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand All @@ -51,6 +81,41 @@
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>brut</groupId>
<artifactId>apktool</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>tools</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>base-cmd</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>translator</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>reader</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>reader-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>ir</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.bitbucket.mstrobel</groupId>
<artifactId>procyon-compilertools</artifactId>
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions repo/brut/apktool/2.0.2/apktool-2.0.2.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>brut</groupId>
<artifactId>apktool</artifactId>
<version>2.0.2</version>
<description>POM was created from install:install-file</description>
</project>
12 changes: 12 additions & 0 deletions repo/brut/apktool/maven-metadata-local.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>brut</groupId>
<artifactId>apktool</artifactId>
<versioning>
<release>2.0.2</release>
<versions>
<version>2.0.2</version>
</versions>
<lastUpdated>20160103230018</lastUpdated>
</versioning>
</metadata>
File renamed without changes.
9 changes: 9 additions & 0 deletions repo/com/googlecode/dex2jar/base-cmd/2.0/base-cmd-2.0.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>base-cmd</artifactId>
<version>2.0</version>
<description>POM was created from install:install-file</description>
</project>
12 changes: 12 additions & 0 deletions repo/com/googlecode/dex2jar/base-cmd/maven-metadata-local.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>base-cmd</artifactId>
<versioning>
<release>2.0</release>
<versions>
<version>2.0</version>
</versions>
<lastUpdated>20160103230548</lastUpdated>
</versioning>
</metadata>
File renamed without changes.
9 changes: 9 additions & 0 deletions repo/com/googlecode/dex2jar/ir/2.0/ir-2.0.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>ir</artifactId>
<version>2.0</version>
<description>POM was created from install:install-file</description>
</project>
12 changes: 12 additions & 0 deletions repo/com/googlecode/dex2jar/ir/maven-metadata-local.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>ir</artifactId>
<versioning>
<release>2.0</release>
<versions>
<version>2.0</version>
</versions>
<lastUpdated>20160103231113</lastUpdated>
</versioning>
</metadata>
9 changes: 9 additions & 0 deletions repo/com/googlecode/dex2jar/reader-api/2.0/reader-api-2.0.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>reader-api</artifactId>
<version>2.0</version>
<description>POM was created from install:install-file</description>
</project>
12 changes: 12 additions & 0 deletions repo/com/googlecode/dex2jar/reader-api/maven-metadata-local.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>reader-api</artifactId>
<versioning>
<release>2.0</release>
<versions>
<version>2.0</version>
</versions>
<lastUpdated>20160103231029</lastUpdated>
</versioning>
</metadata>
File renamed without changes.
9 changes: 9 additions & 0 deletions repo/com/googlecode/dex2jar/reader/2.0/reader-2.0.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>reader</artifactId>
<version>2.0</version>
<description>POM was created from install:install-file</description>
</project>
12 changes: 12 additions & 0 deletions repo/com/googlecode/dex2jar/reader/maven-metadata-local.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>reader</artifactId>
<versioning>
<release>2.0</release>
<versions>
<version>2.0</version>
</versions>
<lastUpdated>20160103230908</lastUpdated>
</versioning>
</metadata>
File renamed without changes.
9 changes: 9 additions & 0 deletions repo/com/googlecode/dex2jar/tools/2.0/tools-2.0.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>tools</artifactId>
<version>2.0</version>
<description>POM was created from install:install-file</description>
</project>
12 changes: 12 additions & 0 deletions repo/com/googlecode/dex2jar/tools/maven-metadata-local.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>tools</artifactId>
<versioning>
<release>2.0</release>
<versions>
<version>2.0</version>
</versions>
<lastUpdated>20160103230106</lastUpdated>
</versioning>
</metadata>
9 changes: 9 additions & 0 deletions repo/com/googlecode/dex2jar/translator/2.0/translator-2.0.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>translator</artifactId>
<version>2.0</version>
<description>POM was created from install:install-file</description>
</project>
12 changes: 12 additions & 0 deletions repo/com/googlecode/dex2jar/translator/maven-metadata-local.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.googlecode.dex2jar</groupId>
<artifactId>translator</artifactId>
<versioning>
<release>2.0</release>
<versions>
<version>2.0</version>
</versions>
<lastUpdated>20160103230807</lastUpdated>
</versioning>
</metadata>
5 changes: 1 addition & 4 deletions src/main/java/com/danwatling/apkdecompiler/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ public static void main(String[] args) {

DecompileApk decompiler = new DecompileApk(filter);
long start = System.currentTimeMillis();
boolean result = decompiler.run();
decompiler.run();

long end = System.currentTimeMillis();

Logger.info("Process took: " + (end - start) + " ms.");
if (!result) {
Logger.info("Something bad happened!");
}
}
}
}
18 changes: 14 additions & 4 deletions src/main/java/com/danwatling/apkdecompiler/adb/Adb.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
Expand All @@ -14,7 +15,7 @@ public class Adb {

public Adb() {
try {
process = Runtime.getRuntime().exec("adb shell");
process = new ProcessBuilder().command(Arrays.asList("adb","shell")).redirectErrorStream(true).start();
getProcessOutput(process.getInputStream());
} catch (IOException ex) {
Logger.error("Unable to run 'adb shell'", ex);
Expand Down Expand Up @@ -50,6 +51,11 @@ private String getProcessOutput(InputStream stream, boolean printWhileRunning) {
if (result.toString().contains("shell@") || result.toString().contains("100%")) {
done = true;
}

if (result.toString().contains("error: no devices found")) {
Logger.error("No devices found. Do you have any connected?");
done = true;
}
}
} catch (IOException ex) {
Logger.error("Unable to read line from adb!", ex);
Expand All @@ -58,9 +64,9 @@ private String getProcessOutput(InputStream stream, boolean printWhileRunning) {
return result.toString();
}

private void exec(String command) {
private boolean exec(String command) {
if (!process.isAlive()) {
Logger.error("adb process is not alive!");
return false;
}

try {
Expand All @@ -70,10 +76,14 @@ private void exec(String command) {
} catch (IOException ex) {
Logger.error("Unable to run '" + command + "'", ex);
}

return true;
}

public List<AndroidPackage> listPackages(String filter) {
exec("pm list packages -3 -f " + filter);
if (!exec("pm list packages -3 -f " + filter)) {
return null;
}
String output = getProcessOutput(process.getInputStream());
BufferedReader reader = new BufferedReader(new StringReader(output));
Logger.info(output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public boolean run() {

try {
List<AndroidPackage> packages = adb.listPackages(this.filter);
if (packages == null) {
return false;
}

if (packages.size() > 1) {
Logger.info("Found " + packages.size() + " applications that match: " + this.filter);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/decompile.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@ECHO OFF

java -jar ApkDecompiler.jar %$
java -jar ApkDecompiler.jar %*
Binary file removed src/main/resources/lib/d2j-jasmin-2.0.jar
Binary file not shown.
Binary file removed src/main/resources/lib/d2j-smali-2.0.jar
Binary file not shown.
Binary file removed src/main/resources/lib/dex-writer-2.0.jar
Binary file not shown.

0 comments on commit 8ad9b87

Please sign in to comment.