我正在使用maven-android-plugin,我正在使用一個鬼鬼祟祟的令牌替換機制來做到這一點。
我使用了「morseflash」樣品,並已將此添加到Maven的資源插件配置:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
<configuration>
<delimiters>
<delimiter>${*}</delimiter>
<delimiter>>08*<</delimiter>
</delimiters>
</configuration>
</plugin>
資源插件允許你定義怪異的分隔符查找/替換。默認分隔符是${*}
,但我添加了>*<
,因此它將匹配XML元素內容。 (其實我用>08*<
;我會在一會兒解釋爲什麼。)
然後,在我的strings.xml,我寫了這個:
<string name="googleMapsAPIKey">08DEBUGKEYABCDEFBLAHBLAHBLAH</string>
而且在釋放模式定義Maven的屬性,如:
<profile>
<id>release</id>
<!-- via this activation the profile is automatically used when the release is done with the maven release
plugin -->
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<properties>
<DEBUGKEYABCDEFBLAHBLAHBLAH>>08RELEASEKEYABCDEFBLAHBLAHBLAH<</DEBUGKEYABCDEFBLAHBLAHBLAH>
</properties>
<-- ... -->
</profile>
這創建了一個名爲Maven的財產調試Maps鍵後,其值是釋放調試鍵。
不幸的是,Maven屬性不允許以數字開頭。我的調試密鑰和釋放密鑰都以08Wfj...
開頭,所以我使用了分隔符>08*<
,並確保在我的替換字符串中包含>08
。
好一個關鍵,這不是太糟糕的方式來做到這一點。我想我會使用這種方法,直到Android/Google/Eclipse團隊提出更多自動化。 – user409849 2010-08-09 22:30:30