fweigl
fweigl

Reputation: 22008

Android/ Eclipse: Removing /src folder from build path

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

Upvotes: 5

Views: 1491

Answers (3)

Robert Rowntree
Robert Rowntree

Reputation: 6289

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

Upvotes: 0

stoilkov
stoilkov

Reputation: 1686

"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>

Upvotes: 3

NathanTempelman
NathanTempelman

Reputation: 1387

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!

Upvotes: 0

Related Questions