2013-08-29 3 views
0

위해 나는 ANT 멍청한 놈은 내가 내 안드로이드 프로젝트를 위해이 작은 수수께끼를 해결할 수있는 온라인 찾기 위해 애 쓰고 있어요. 내가하고 싶은 무엇실행 관세 규칙은 특정 대상

내가 실행 어떤 개미 명령에 따라 몇 가지 규칙을 실행됩니다. 기본적으로 ANT DEBUG를 실행하면 사용자 지정 규칙을 실행하고 싶지 않습니다. ANT RELEASE를 실행하면 사용자 정의 규칙을 실행하고 싶습니다. 순간

내 사용자 정의 규칙은 사전 빌드 단계에 상관없이 실행할 수 없습니다.

여기에 여기에 내가 그것을 해결했습니다 좋아 내 custom_rules.xml

<project> 
<macrodef name="git" description="run a git command"> 
    <attribute name="command" /> 
    <attribute name="dir" default="" /> 
    <element name="args" optional="true" /> 
    <element name="gitOutputRedirector" optional="true"/> 
    <sequential> 
     <echo message="git @{command}" /> 
     <exec executable="git" dir="@{dir}"> 
      <arg value="@{command}" /> 
      <args/> 
      <gitOutputRedirector/> 
     </exec> 
    </sequential> 
</macrodef> 

<target name="-pre-build" depends="set-version-using-file,git-last-commit-hash-rev-parse" > 

</target> 

<target name="set-version-using-file"> 
    <!-- Load properties from "version.properties" file -->  
    <property file="version.properties" /> 
    <replaceregexp file="AndroidManifest.xml" match="android:versionCode(.*)" 
          replace='android:versionCode="${Version.Code}"'/> 
    <replaceregexp file="AndroidManifest.xml" match='android:versionName="\d+\.+\d+\.+\d+\.+\d"' 
          replace='android:versionName="${Version.Name}"'/>   
    <echo message="Set android:versionCode as ${Version.Code}" /> 
    <echo message="Set android:versionName as ${Version.Name}" /> 
</target> 


<!-- Get the last commit --> 
<target name="git-last-commit-hash-rev-parse" description="Commits all changes to version git" > 
    <property file="version.properties" /> 
    <git command="rev-parse" > 
     <args> 
      <arg value="HEAD" /> 
     </args> 
     <gitOutputRedirector> 
      <redirector outputproperty="git.last.commit"/> 
     </gitOutputRedirector> 
    </git> 
    <echo message="Last commit found was ${git.last.commit}" /> 
    <echo message="Will now tag ${git.last.commit} with ${Version.Name}" /> 

    <git command="tag"> 
     <args> 
      <!-- This tags the last commit with the full version name --> 
      <arg value="${Version.Name}" /> 
      <!-- For some reason why it doesn't like this command through ant.--> 
      <!-- <arg value="${Version.Name} ${git.last.commit} -m 'Tagged for build'" /> --> 
     </args> 
    </git> 

</target> 
</project> 

답변

1

내 build.xml 파일

<?xml version="1.0" encoding="UTF-8"?> 
<project name="MainActivity" default="help"> 
<property file="local.properties" /> 
<property file="ant.properties" /> 
<property environment="env" /> 

<condition property="sdk.dir" value="${env.ANDROID_HOME}"> 
    <isset property="env.ANDROID_HOME" /> 
</condition> 

<loadproperties srcFile="project.properties" /> 
<fail 
     message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable." 
     unless="sdk.dir" 
/> 

<import file="custom_rules.xml" optional="true" /> 

<import file="${sdk.dir}/tools/ant/build.xml" /> 

입니다!

내가 주 build.xml 파일

에 내 주요 build.xml 파일 내 매크로 데프와 두 개의 목표를 이동 나는 다음과 같은

<target name="releaseCan" depends="set-version-using-file, release, git-last-commit-hash-rev-parse"/> 

이 (가) 그래서 실행 다음 버전 대상을 변경 추가

<target name="set-version-using-file" depends="-pre-build"> 

이 다음에 자식 대상을 변경 사전 구축, 그래서 포스트 빌드를 실행합니다.

<target name="git-last-commit-hash-rev-parse" description="Commits all changes to version git" depends="-post-build"> 

그래서 나는 다음과 같은

는 AndroidManifest.xml을 (- 전 빌드()는 컴파일을 수행하고 서명 등 등) 실행 실행 일반 릴리스 목표를 수정 않습니다 개미 releaseCan을 실행 릴리스 대상이 실패 할 경우 빌드 후 여전히 실행하면

그래서 그것의 아주 기본적인 자식 명령 (자격증 신청인 - 빌드), 잘 모르겠어요.