Tuesday, April 21, 2015

Ant Script that compiles an APK from Smali code, signs it, and installs it onto the phone

<?xml version="1.0"?>
<project name="build_original_apk" default="signing_apk" >
    
    
    <property name="out.packaged.file" value="/Users/liu/Work/PlayHelloWorldSmali/original-debug/dist/original-debug.apk" />
    
    <property name="name.signed.file" value="/Users/liu/Work/PlayHelloWorldSmali/original-debug/dist/original-debug-signed.apk"/>
    <property name="key.store" value="/Users/liu/Work/android.jks"/>
    <property name="key.store.password" value="123456"/>
    <property name="key.alias" value="MyAndroidKey"/>
    <property name="key.alias.password" value="123456"/>
    <property name="verbose" value="true"/>
    
    
    
    <target name="build_apk">
        <java jar="/Users/liu/Work/apktool_2.0.0rc4.jar" fork="true">
            <arg value="b"/>
            <arg path="/Users/liu/Work/PlayHelloWorldSmali/original-debug"/>
        </java>
        <echo>building original apk complete!</echo>
    </target>
    
    
    <target name="signing_apk" depends="build_apk">
        <signjar
        sigalg="MD5withRSA"
        digestalg="SHA1"
        jar="${out.packaged.file}"
        signedjar="${name.signed.file}"
        keystore="${key.store}"
        storepass="${key.store.password}"
        alias="${key.alias}"
        keypass="${key.alias.password}"
        verbose="${verbose}" />
    </target>
    
    <target name="install" depends="signing_apk">
        <exec executable="adb">
            <arg value="install"/>
            <arg path="${name.signed.file}"/>
        </exec>
    </target>
</project>



To run the install target, in the command line:


ant -buildfile build_original.xml install

No comments:

Post a Comment