Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 374
fweigl Avatar asked Oct 22 '22 17:10

fweigl


1 Answers

"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>
like image 95
stoilkov Avatar answered Oct 29 '22 19:10

stoilkov