5

This might sound like a stupid question, but what exactly happens when I remove the /src folder of an Android project from the 'build path' (only MainActivity/gen is left there)? I can still compile and run the project, so what does the build path do?

Background: I'm going a bit crazy about the import of a maven-built project to Eclipse. It has the /src/main/package kind of folder structure, so when I import it all the declared package names don't match (obviously a well known problem). My first attempt was to just move the packages up in the folder structure (directly to /src) before importing the project, but that gave me a ton of other problems (concerning import of other packages).

Second attempt was (this was recommended on several questions on SO) to just remove the /src folder from the build path and voila, the package declarations work and there's no more shown problems in Eclipse, but I got a very strange problem on runtime and I don't know if it os related to me removing the /src folder from the build path.

Edit: Here's the error when running the app. I should add that MyApplication is not an Activity but it extends Application (used to store globals). Google maps is used in that project, but not in the first activity.

02-20 14:39:34.781: E/AndroidRuntime(1479): FATAL EXCEPTION: main
02-20 14:39:34.781: E/AndroidRuntime(1479): java.lang.RuntimeException: Unable to instantiate application com.example.myapp.MyApplication: java.lang.ClassNotFoundException: Didn't find class "com.example.myapp.MyApplication" on path: /system/framework/com.google.android.maps.jar:/data/app/com.example.myapp-1.apk
02-20 14:39:34.781: E/AndroidRuntime(1479):     at android.app.LoadedApk.makeApplication(LoadedApk.java:504)
02-20 14:39:34.781: E/AndroidRuntime(1479):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4364)
02-20 14:39:34.781: E/AndroidRuntime(1479):     at android.app.ActivityThread.access$1300(ActivityThread.java:141)
02-20 14:39:34.781: E/AndroidRuntime(1479):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
02-20 14:39:34.781: E/AndroidRuntime(1479):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-20 14:39:34.781: E/AndroidRuntime(1479):     at android.os.Looper.loop(Looper.java:137)
02-20 14:39:34.781: E/AndroidRuntime(1479):     at android.app.ActivityThread.main(ActivityThread.java:5039)
02-20 14:39:34.781: E/AndroidRuntime(1479):     at java.lang.reflect.Method.invokeNative(Native Method)
02-20 14:39:34.781: E/AndroidRuntime(1479):     at java.lang.reflect.Method.invoke(Method.java:511)
02-20 14:39:34.781: E/AndroidRuntime(1479):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-20 14:39:34.781: E/AndroidRuntime(1479):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-20 14:39:34.781: E/AndroidRuntime(1479):     at dalvik.system.NativeStart.main(Native Method)
02-20 14:39:34.781: E/AndroidRuntime(1479): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.myapp.MyApplication" on path: /system/framework/com.google.android.maps.jar:/data/app/com,example.myapp-1.apk
02-20 14:39:34.781: E/AndroidRuntime(1479):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
02-20 14:39:34.781: E/AndroidRuntime(1479):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-20 14:39:34.781: E/AndroidRuntime(1479):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-20 14:39:34.781: E/AndroidRuntime(1479):     at android.app.Instrumentation.newApplication(Instrumentation.java:968)
02-20 14:39:34.781: E/AndroidRuntime(1479):     at android.app.LoadedApk.makeApplication(LoadedApk.java:499)
02-20 14:39:34.781: E/AndroidRuntime(1479):     ... 11 more
fweigl
  • 21,278
  • 20
  • 114
  • 205
  • If you could add some details about your very strange runtime problem that might help people to determine if the problem is related to the src folder being removed. – NathanTempelman Feb 19 '13 at 18:09
  • Use `File - Import... - Maven - Existing Maven Projects` to import the existing mavenized Android project, check out [this answer](http://stackoverflow.com/questions/11921769/do-i-need-to-install-an-adt-plugin-if-i-want-to-use-maven/11926069#11926069) to see how to get the required Eclipse plugin. – yorkw Feb 19 '13 at 20:15
  • you should post the log where you get runtime error, could be due to declarations in manifest file – nandeesh Feb 20 '13 at 14:33
  • `ClassNotFoundException`, you are looking for your class in an external JAR? – Shark Feb 26 '13 at 11:38
  • @Shark That's exactly the part that I can't understand. – fweigl Feb 26 '13 at 12:43

3 Answers3

3

"what exactly happens when I remove the /src folder of an Android project from the 'build path' (only MainActivity/gen is left there)?"

You create an "empty apk" where you only have access to resources :)

About maven, you have two options:

  • Work with maven source structure and tell Eclipse where sources are.Import the project as "Existing Android code", than go to Java Build Path, remove the "src" folder and add the folders "src/main/java/" and "src/test/java".
  • Work with eclipse default package structure and tell maven where sources are. In your pom.xml, under add following directive to tell maven where it should look for sources: <sourceDirectory>src</sourceDirectory>
stoilkov
  • 1,686
  • 1
  • 11
  • 18
  • "You create an "empty apk" where you only have access to resources :)" I dont think that's correct, because I can compile and run the application ... – fweigl Feb 26 '13 at 11:15
0

To answer part of your question, I believe regardless of whether or not the src folder is built, the gen files and apk are, and they're built from the src files. Kind of a cascading build from what I understand. I could be wrong. I don't have much experience with maven though, so I couldnt answer the rest. Hopefully someone else can tell you. Good luck!

NathanTempelman
  • 1,301
  • 9
  • 34
0

why not install 'm2e' in eclipse

then import the maven project into eclipse using the 'import' menu in the eclipse 'explorer'.

then you should be able to build in 2 ways:

on the CLI using 'mvn' target

in eclipse

Robert Rowntree
  • 6,230
  • 2
  • 24
  • 43