使用scala编写Android项目

8 篇文章 0 订阅
8 篇文章 0 订阅

开发环境

Idea 10.5

Maven 3

pom.xml文件如下

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>scala</artifactId>
    <version>1.0</version>
    <packaging>apk</packaging>
    <name>scala</name>
    <repositories>
        <repository>
            <id>scala-tools.org</id>
            <name>Scala-tools Maven2 Repository</name>
            <url>http://scala-tools.org/repo-releases</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>scala-tools.org</id>
            <name>Scala-tools Maven2 Repository</name>
            <url>http://scala-tools.org/repo-releases</url>
        </pluginRepository>
    </pluginRepositories>
    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>2.2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android-test</artifactId>
            <version>2.2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.8.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <version>2.13.1</version>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>scala-test-compile</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.pyx4me</groupId>
                <artifactId>proguard-maven-plugin</artifactId>
                <version>2.0.4</version>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>proguard</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <maxMemory>256m</maxMemory>
                    <injar>android-classes</injar>
                    <libs>
                        <lib>${rt.jar.path}</lib>
                    </libs>
                    <obfuscate>false</obfuscate>
                    <options>
                        <option>-keep public class * extends android.app.Activity</option>
                        <option>-keep public class * extends android.app.Application</option>
                        <option>-keep public class * extends android.app.Service</option>
                        <option>-keep public class * extends android.content.BroadcastReceiver</option>
                        <option>-keep public class * extends android.content.ContentProvider</option>
                        <option>-dontskipnonpubliclibraryclasses</option>
                        <option>-dontoptimize</option>
                        <option>-printmapping map.txt</option>
                        <option>-printseeds seed.txt</option>
                        <option>-ignorewarnings</option>
                    </options>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>maven-android-plugin</artifactId>
                <version>2.8.4</version>
                <configuration>
                    <sdk>
                        <platform>8</platform>
                    </sdk>
                    <emulator>
                        <avd>Android2.2</avd>
                    </emulator>
                    <deleteConflictingFiles>true</deleteConflictingFiles>
                    <undeployBeforeDeploy>true</undeployBeforeDeploy>
                </configuration>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3</version>
            </plugin>
        </plugins>
    </build>

         <properties>
                <rt.jar.path>${env.JAVA_HOME}/jre/lib/rt.jar</rt.jar.path>
                <jsse.jar.path>${env.JAVA_HOME}/jre/lib/jsse.jar</jsse.jar.path>
            </properties>

</project>


如果遇到以下问题

[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:maven-android-plugin:2.8.4:dex (default-dex) on project scala: MojoExecutionException: ANDROID-040-001: Could not execute: Command = cmd.exe /X /C "D:\Java\androidSdk\platform-tools\dx.bat --dex --output=D:\Java\IDEA\Project\scalatest\scala\target\classes.dex D:\Java\IDEA\Project\scalatest\scala\target\android-classes", Result = 2 -> [Help 1]

是因为pom.xml文件中缺少proguard组件(shift!为啥一定要混淆。。不混淆就不能用啦)

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值