当前位置: 代码迷 >> Android >> Android Talker(二)Project Environment
  详细解决方案

Android Talker(二)Project Environment

热度:68   发布时间:2016-05-01 12:38:51.0
Android Talker(2)Project Environment
Android Talker(2)Project Environment

1. Some tips about the eclipse and old project
Error Message:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.1.1:generate-sources (default-generate-sources) on project ProjectName: The plugin com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.1.1 requires Maven version [3.0.3,)

solution:
Change the version of maven from eclipse inside maven to outside maven 3.0.3.

Install the plugin android configurator for M2E with URL
Uninstall the old maven plugin and reinstall this Plugin

http://rgladwell.github.com/m2e-android/updates
http://rgladwell.github.com/m2e-android/

It is fixed.

Error Message:
case expressions must be constant expressions

solution:
Click on the red error icon, click on the tip 'migrate android code'

Put my click on switch, use command + 1, click 'convert switch to if else'

Error Message:
Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-jar-plugin:2.4:jar (execution:default-jar, phase: process-class)

Solution:
The pom is not the latest one, I change it as follow, it works.
<plugin>
     <groupId>com.jayway.maven.plugins.android.generation2</groupId>
     <artifactId>android-maven-plugin</artifactId>
     <version>3.1.1</version>
     <configuration>                    <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
<assetsDirectory>${project.basedir}/assets</assetsDirectory>
<resourceDirectory>${project.basedir}/res</resourceDirectory>                    <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
<sdk>
     <platform>8</platform>
</sdk>
</configuration>
<extensions>true</extensions>
</plugin>

Run the project rest client, sometimes, we need to restart the adb.
>adb \
kill-server
>adb \
start-server

Run the maven command to redeploy the latest packages to android emulator.
>mvn android:deploy
>mvn android:run

The rest server returns the JSON format data as follow:
[{"id":1,"personName":"UserName1"},{"id":2,"personName":"UserName2"}]

But I got error message as follow from getAll() List<Person> interface.

Error Message:
java.lang.ClassCastException: java.util.LinkedHashMap

Solution:
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
// Perform the HTTP GET request
Person[] persons = restTemplate.getForObject(url, Person[].class);
// convert the array to a list and return it
return Arrays.asList(persons);

2. Debug that on Real Device
>adb devices
This command will list the devices.

>adb logcat
Show the real time log on the mobile device.

I am on MAC system, and I use maven to control the android project.
The name of the sample project is EasyRestClientAndroid
>clean install android:deploy android:run

How to enable the android phone
>settings ----> applications-----> check Unknown sources
>settings ----> Development ---> check USB debugging
                                                check stay awake
                                                check Allow mock locations


references:
http://stackoverflow.com/questions/11031709/android-maven-plugin-3-2-0-with-maven-3-0-4-not-compile-it
http://rgladwell.github.com/m2e-android/
http://stackoverflow.com/questions/6622287/issue-when-consume-rest-service-with-resttemplate-in-desktop-app


http://thompsonng.blogspot.com/2011/08/android-debug-with-hardware-device-in.html
http://developer.android.com/tools/device.html
http://www.mkyong.com/android/android-debugging-on-real-device/

  相关解决方案