5

コマンドラインからAndroidプロジェクトをビルドしたい。通常、私は 2 つの環境 (マーチャントとプロダクション) 用にプロジェクトをビルドします。マーチャントとプロダクションの URL については、コマンド ラインから自動的に実行したいと考えています。プロジェクトで毎回手動で指定する必要はありません。たとえば、本番環境用のプロジェクトをビルドする、またはコマンド自体で環境を指定してマーチャント環境用のプロジェクトをビルドするとします。それはできますか?助けてください。

4

2 に答える 2

4

Maven、Ant、Gradleを使用してプロジェクトをビルドできます。それらのすべてはあなたが望むことをします。
私はMavenを使用しているため、Mavenの構成に焦点を当てます。Mavenがどのように機能するかわからない場合は、複雑な作業になる可能性があります。

Mavenを構成する

ここで説明する最初の前提条件:
https ://code.google.com/p/maven-android-plugin/wiki/GettingStarted

android mavenプラグインを使用してビルドするようにプロジェクトを構成します:
https ://code.google.com/p/maven-android-plugin/

Eclipseの構成例:
https ://code.google.com/p/maven-android-plugin/wiki/QuickStartForEclipseProject

以下のコマンドを使用してサンプルプロジェクトを生成することもできます。

mvn archetype:generate \
  -DarchetypeArtifactId=android-quickstart \
  -DarchetypeGroupId=de.akquinet.android.archetypes \
  -DarchetypeVersion=1.0.8 \
  -DgroupId=com.myproject \
  -DartifactId=my-android-application

プロフィール作成

2番目のステップは、本番用のビルドプロファイルを作成することです。

重要:次のプロファイルスニペットベースは、上記のコマンドコマンドで生成されたpom.xmlで機能しmvn archetype:generateます。

以下にリストされているプロファイルは、res / values/strings.xmlにあるファイル内の文字列を置き換えます

形:

<string name="hello">Whatever text</string>

に:

 <string name="hello">productionURL</string>

プロファイル(上記のpom.xmlに含めてください</project>):

<profiles>
    <profile>
        <id>production</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.google.code.maven-replacer-plugin</groupId>
                    <artifactId>replacer</artifactId>
                    <version>1.5.2</version>
                    <executions>
                        <execution>
                            <phase>process-sources</phase>
                            <goals>
                                <goal>replace</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <file>${project.basedir}/res/values/strings.xml</file>
                        <regex>true</regex>
                        <replacements>
                            <replacement>
                                <token><![CDATA[(<string name="hello">)(.+)(</string>)]]></token>
                                <value><![CDATA[$1productionURL$3]]></value>
                            </replacement>         
                        </replacements>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <inherited>true</inherited>
                    <configuration>
                        <sign>
                            <debug>true</debug>
                        </sign>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

文字列の代わりにhttps://code.google.com/p/maven-replacer-plugin/を使用します。

<profile>販売者の場合は、上記のコピー&ペーストで、 URLを更新に変更<id>production</id>してください。<id>merchant</id><value>

建てる

mvn install -Pproduction

また

mvn install -Pmerchant
于 2013-02-12T19:04:41.483 に答える
1

Ant では、標準の android Ant ファイルのリリース ターゲットを実行する前に生成されるテンプレート リソース ファイルまたはテンプレート Java ファイルをコピーすることで、プロジェクトをカスタマイズできます。

生成されたファイルは、バージョン管理に対して無視する必要があります。

ant リリースでアプリケーションをビルドする前に呼び出す必要があるサンプル ANT ターゲットを次に示します。1 つの Java ファイルと 1 つのリソース ファイルを生成します。

<target name="updateMyConfiguration"">
    <copy file="./MyTemplateConfiguration.java"
        tofile="./src/com/mycompany/android/myapp/MyCodeConfiguration.java"
        overwrite="true">
    </copy>
    <replace file="./src/com/mycompany/android/myapp/MyCodeConfiguration.java">
        <replacefilter token="token_my_boolean"
            value="${code.configuration.my_boolean}" />
        <replacefilter token="token_my_integer"
            value="${code.configuration.my_integer}" />
        <replacefilter token="token_my_string"
            value="${code.configuration.my_string}" />
    </replace>
    <copy file="./MyTemplateRes.xml"
        tofile="./res/values/MyResConfiguration.xml"
        overwrite="true">
    </copy>
    <replace file="./res/values/MyResConfiguration.xml">
        <replacefilter token="token_my_string"
            value="${res.configuration.my_string}" />
        <replacefilter token="token_my_integer"
            value="${res_configuration.my_integer}" />
    </replace>
</target>

package com.mycompany.android.myapp;

public final class MyCodeConfiguration
{
    static final boolean my_boolean = token_my_boolean;
    static final String my_string = "token_my_string";
    static final int my_integer = token_my_integer;
}

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <add-resource type="string" name="my_string"/>
    <string name="my_string">token_my_string</string>
    <add-resource type="integer" name="my_integer"/>
    <integer name="my_integer">token_my_integer</integer>
</resources>

次に、次のように Ant を実行するだけです。

ant updateMyConfiguration -Dres.configuration.string=MyCustomBuildString -Dcode.configuration.my_integer=1234
于 2013-02-18T07:58:51.213 に答える