当前位置: 动力学知识库 > 问答 > 编程问答 >

compiler errors - Android compilation failure in maven

问题描述:

I am making an Android app, and have created a custom view to do some animation.

I have created a custom view, extending ImageView and implementing ValueAnimator.AnimatorUpdateListener.

When I try to compile this with maven it fails with "package android.animation does not exist"

However, when building within Intellij Idea it builds fine. After building in Idea it is even possible to run mvn install successfully.

The successful build running fine in the emulator, but not on my physical device.

When trying to start it up on the device I get:

Failed resolving Lno/derp/myapp/view/MyAnimatedView; interface 7 'Landroid/animation/ValueAnimator$AnimatorUpdateListener;'

Link of class 'Lno/derp/myapp//view/MyAnimatedView;' failed

Could not find class 'no/derp/myapp/view/MyAnimatedView', referenced from method no/derp/myapp.MainActivity.onCreate

and then

java.lang.ClassNotFoundException: no/derp/myapp.MyAnimatedView in loader dalvik.system.PathClassLoader[/data/app/no/derp/myapp-2.apk]

pom.xml:

 <packaging>apk</packaging>

<name>My App</name>

<dependencies>

<dependency>

<groupId>com.google.android</groupId>

<artifactId>android</artifactId>

<version>2.3.3</version>

<scope>provided</scope>

</dependency>

</dependencies>

<build>

<plugins>

<plugin>

<groupId>com.jayway.maven.plugins.android.generation2</groupId>

<artifactId>android-maven-plugin</artifactId>

<version>3.0.0</version>

<configuration>

<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>

<assetsDirectory>${project.basedir}/assets</assetsDirectory>

<resourceDirectory>${project.basedir}/resources</resourceDirectory>

<undeployBeforeDeploy>true</undeployBeforeDeploy>

</configuration>

<extensions>true</extensions>

</plugin>

<plugin>

<artifactId>maven-compiler-plugin</artifactId>

<version>2.3.2</version>

<configuration>

<target>1.6</target>

<source>1.6</source>

</configuration>

</plugin>

</plugins>

I am using the latest version of the SDK. A class importing the mentioned package does not compile, it is not just the view. The same happens with version 2.8.3 of android-maven-plugin (or maven-android-plugin as it was called)

Any ideas?

网友答案:

android.animation is available since API Level 11, you need set your dependency in your pom.xml to use 3.0+ to compile your code in command-line.

The reason why it works in Intellij is IDE usually use default.properties to resolve the SDK used to compile source code, I suppose you use the correct API level in your default.properties.

Hope this help.

网友答案:

It seems you are missing the configuration of the plugin for the platform/api level. Check out e.g. helloflashlight example of the official samples.

In your case you would have to add

                <sdk>
                    <!-- platform or api level (api level 4 = platform 1.6)-->
                    <platform>4</platform>
                </sdk>

with api level 9 or 10 or whatever you need. See the API level doc.

And for the compile plugin to have the right API you have to have the correct android dependency. You potentially have to use my Maven Android SDK Deployer to push the dependency into your local repository

网友答案:

Maven Android SDK Deployer helped since I got

  <dependency>
      <groupId>android</groupId>
      <artifactId>android</artifactId>
      <version>4.0_r2</version>
      <scope>provided</scope>
  </dependency>

But the application still crashes on my phone, same as before, "Link of .. failed". Which is natural, since I probably have Android 2.X on my phone. The reason Idea compiles is because it has the Android SDK set manually, it does not use the maven plugin, I think.

分享给朋友:
您可能感兴趣的文章:
随机阅读: