0
点赞
收藏
分享

微信扫一扫

maven-android-sdk-deployer 安装记录


[color=red]Android development with maven[/color] [url]http://www.blogjava.net/askcuix/archive/2011/03/07/345897.html[/url]

maven-android-sdk-deployer官方:[url]https://github.com/mosabua/maven-android-sdk-deployer[/url]
1.下载android ADT [url]http://developer.android.com/sdk/index.html[/url]
2.下载maven-android-sdk-deployer
3.配置maven
4.[color=red]要vpn,否则很难下载上面的东西和更新ADT[/color],不要问我为什么,我也搞不明白搞个技术都要跳墙。
5.安装命令和教程见官方,执行mvn命令的时候,注意,如果出错,就到D:\maven-android-sdk-deployer-master\extras\pom.xml注释掉出错内容,否则无法mvn clean install。

<modules>
                <module>compatibility-v4</module>
                <module>compatibility-v7-gridlayout</module>
                <module>compatibility-v7-appcompat</module>
                <module>compatibility-v7-mediarouter</module>
                <module>compatibility-v13</module>
				<!--  deprecated by Google, will leave in for a while in case someone wants to manually activate and use it -->
                <!-- <module>analytics-v2</module> -->
                <!--  deprecated by Google with Aug 2014, but still available for download
                might remove then, see http://googleadsdeveloper.blogspot.ca/2014/02/since-joining-google-play-services-back.html  -->
                <!-- <module>admob-ads-sdk</module> -->
                <!--  deprecated by Google, will leave in for a while in case someone wants to manually activate and use it -->
                <!-- <module>gcm</module>  -->
                <module>google-play-services</module>
                <module>google-play-services-froyo</module>
                <module>play-licensing</module>
                <module>play-apk-expansion</module>
            </modules>


[color=red]因为<module>admob-ads-sdk</module>总是出错,可能也用不到,所以就先注释掉。[/color]


6. setting.xml


<pluginGroups>
       <pluginGroup>com.jayway.maven.plugins.android.generation2</pluginGroup>  
</pluginGroups>




[size=x-large][color=blue]一个pom.xml文件[/color][/size]: [color=red]注意,AndroidManifest.xml,project.properties和pom里面的sdk的level要一致。[/color]


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>WebView2</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>apk</packaging>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>4.1.1.4</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <finalName>${project.artifactId}</finalName>
        <!-- <sourceDirectory>src</sourceDirectory> -->
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <version>3.8.0</version>
                    <extensions>true</extensions>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <configuration>
                    <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
                    <assetsDirectory>${project.basedir}/assets</assetsDirectory>
                    <resourceDirectory>${project.basedir}/res</resourceDirectory>
                    <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
                    <run>
                        <debug>true</debug>
                    </run>
                    <sdk>
                        <!-- 值就是所使用的sdk的level,它对应android sdk目录中的platforms/android-*目录 -->
                        <platform>18</platform>
                    </sdk>
                    <emulator>
                        <!-- 元素就对应你的AVD Manager名字 -->
                        <avd>ADTTest</avd>
                    </emulator>
                    <deleteConflictingFiles>true</deleteConflictingFiles>
                    <undeployBeforeDeploy>true</undeployBeforeDeploy>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                    <optimize>true</optimize>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <!--  
                我们想将所有的依赖库都打包,直接交给用户,这样用户不需要在做其他设置了,这里需要使用Assembly插件了,其说明参考Pre-defined Descriptor Files,这个参考文件也说明了有四种默认定义的打包方式,我们选择jar-with-dependencies,继续添加pom文件 
                -->
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>


这里讲讲maven-android_plugin,我这里使用的android版本是2.2.1,对应的level就是8。<platform>的值就是所使用的sdk的level,它对应android sdk目录中的platforms/android-*目录。<path>的默认值就是ANDROID_HOME环境变量,这里也可以hardcode一个绝对路径。要在模拟器中运行应用,就需要定义一个AVD Manager,<emulator>下的<avd>元素就对应你的AVD Manager名字。



要编译android应用就需要将目标平台的jar包含在pom中,就像之前提及到的,仅仅作为编译使用,所以我们将这个dependency的scope设成provided。



[color=red]运行步骤:[/color]


现在我们就可以测试一下这个helloworld级别的应用了。


首先在命令行中build这个应用。


[color=darkblue]mvn clean install[/color]



然后启动模拟器,maven将会尝试启动配置在pom.xml中的AVD,因此pom中的avd的名字一定要和实际的avd相同。


[color=darkblue]mvn android:emulator-start[/color]



最后,我们将应用部署到模拟器上。[color=red]好像要上面的命令启动,才能够部署[/color]。


[color=darkblue]mvn android:deploy[/color]



在运行应用前,我们可以打开android的log viewer,这对我们调试应用是很有帮助的。


adb logcat




[b][color=red]问题:[/color][/b]


1.如何进行断点调试?


举报

相关推荐

0 条评论