Building Android Source apps In Eclipse - java

I downloaded the source to spareparts here
https://android.googlesource.com/platform/development/+/gingerbread-release/apps/SpareParts
It includes Android.mk, AndroidManifest.xml, Notice, res and src folders.
My question is how can I compile this source code in Eclipse? I see there is a make file (Android.mk) which I'm guessing I need to use but I can't figure out what to do to get this thing imported into Eclipse without having 500+ errors.

This article seems to have the answer. According to it you would need to download all of the source just to build one of the apps, though.

Brute force always works :)
Create a new android project in Eclipse named SpareParts
Use the explorer to replace both the src/ and res/ folders inside workspace/SpareParts with the ones downloaded form git
Click with the right button on the SpareParts entry in the project tree in Eclipse -> Refresh
enjoy
I looked into the files and it does not seem that it uses any external library.
If you try to build it by itself, you will still have problems due to these three classes that are not in android.jar:
import android.app.ActivityManagerNative; //cannot be resolved
import android.os.ServiceManager; //cannot be resolved
import android.view.IWindowManager; //cannot be resolved

In Eclipse try File->Import... and General->Existing Projects into Workspace, add the project folder and then try to compile it. Hope it helps.

Related

Android Studio: How to import java class from outside the project?

I'm working on an android game that requires a server. We've set up a git in which there are three folders: Client, Server and Shared:
Client contains the Android-Studio project.
Server contains an Eclipse project which is our server and database.
Shared contains java classes that I would like to use in both the Eclipse and Android-Studio project.
In Eclipse I successfully loaded the files from Shared by importing them as "file system". (It created a package and everything works great)
In Android-Studio, I can't find a solution that doesn't require me to copy-paste the classes in the project. The aim here is to have those file at only one location as they're susceptible to change but must me identical in both the projects... So those solutions don't fit my needs.
I'm looking for something like a way to link files from outside the project. (I managed to link libraries from inside the project already but not from outside)
The simple solution is to copy the desired java files into your project structure. Of course, you may have to change package names manually.
Found a solution that might not be optimal but at least in my case it solved the problem.
In Android-Studio:
Create a folder called something like "CommonEclipseAndroid" following a path similar to this one: project/Android/app/src/main/java/com/example/myapplication/CommonEclipseAndroid
Paste the code you need to use in both project inside this folder.
In Eclipse:
Right click on your project: Properties > Java Build Path > Source > Link Source and choose the folder we've just created.
Now your projects use the same code. You only need to modify it once for both projects and there's no risk of error.
Hope I helped :).
You can import the shared folder as a module .
go to file> new> import module
Now use the same imported folder in eclipse as well.

Import Java Project, not found src

let me tell you that I'm new in Java and I'm having this problem with an Android App.
The app is made by two projects, the launcher activity(Project A) and another one (Project B) which has some common SRCs for multiple Android Apps (like http connection classes, etc).
I imported project B from A, and in my .java files of my project A, I could import without problem src from B (import path from B;)
But when I'm debbuging and it has to use a file from B, I get an NoClassDefFoundError with the path of some file in project B.
After that, my app fails and closes.
Sorry if my English is complicated. Hope you understand my problem and can help me.
I guess it's something about a missing step in my import.
Importing just puts these projects into your workspace. If they are 2 separate projects you should import them as separate projects. Either right click import and navigate to them on your file system or if they are already in your workspace, do create new java project and give it the same name as the directory of the project (The wizard will make it clear that it recognizes a java project exists in that folder).
Then check to make sure that the package names and imports one package to the other are correct. If they weren't you should errors marked on those lines.
Finally make sure that the project which you are actually running from has the other project on its build path. Right click on the project, configure build path, and add the packages. Alternatively you can use something like maven to automate the installation of this second package as a jar which will automatically update in project A when project B is changed)
Please make sure you include the classes/src from project B in your project A's build path , by right clicking on your project A "Build Path" -> "Configure Build Path". Eclipse automatically will add those classes to your class path too.
The NoClassDefFoundError usually occurs when the classes needed to compile the project are present during build time but missing during run time.
Hope this helps !!
To reference other projects source in current project, just import them into your current project by adding them to your workspace. This link has some neat steps to accomplish this. You can follow which one suites you.

Importing code into Eclipse when it's not a project

I'm scratching my head here, trying to figure out how to get an already existing library into Eclipse.
With AndEngine it was easy, as i could simply import it as a project. However, with this one, I cannot do that (the importer doesn't find any projects in the source tree). How would I import code not archived as a project?
The specific import in question is: https://github.com/sm4/AndEngine/tree/GLES2-AnchorCenter
If it matters, I need to reference it from this Android project
Well, you can download their src and then drag and drop their package into your src folder... Thats one way atleast.. If you want to leave it in Jar form, you can drop the Jar into your source folder, add it to build path, and then use it in your project.

Is it possible to run a program by downloading the source folder in eclipse?

I was curious if it is possible to run a project in a different desktop by just downloading the source folder and setting it as the workspace?
If possible, how can I run it? When I try, an ant-builder shows up when running it.
Any help would be nice,
Thank you.
Download the source code project.
Import the project in eclipse.
Project>Clean>Build
Run
Downloading the workspace is probably not a good idea, since you might have different environment and locations.
What I would do is this:
Create a new workspace or use an existing one
Open the workspace above
Use File -> Import ->Existing project to a workspace
Navigate to the root folder of the project that you want to import
Alternatively in step #4 you can navigate to a root folder of several project, in which case you'll see a dialog where you'll need to select all projects that you want to import. This approach allows importing multiple projects in a single import.
Eclipse finds projects by searching for '.project' files in all sub-directories of the root folder that you've provided.
Yes, it is possible. I faced a similar situation earlier. Just follow these steps :
Copy the project to the other desktop.
Go to File -> Import -> General -> Existing Projects into workspace.
Browse and select your project folder and import the files.

NetBeans error: package org does not exist

I just installed Netbeans IDE. I am now unable to import any org.* libs and it just says package org does not exist.
Also, I imported jdic.jar into the project and even though the code completion suggestions show up as org.jdesktop.*, it shows the same error.
How do I fix this?
Clearing the cache fixed it.
In windows 7 the cache is located in
C:\Users\username\AppData\Local\NetBeans\...
On Linux, the cache is at:
/home/username/.cache/netbeans/...
On clearing the cache, and restarting netbeans, it started to recognize org.* imports again.
I did it easily, just click the Jframe, on Navigator tab, right-click -> Set Layout -> Absolute Layout and YEP, It works for me.
org.netbeans.lib.awtextra is part of the AbsoluteLayout library. It should be added automatically by the ide whenever absolutelayout is used in the form. But if you switch to some other layout after using absolute layout, then the jar/library will be removed from the classpath and existing code making calls to the library will not compile.
If you would like to use absolute layout, then please include the library in the project. Select 'Libraries' node in the project, right-click and select 'Add Library' and select 'Absolute Layout' library from the list of available libraries.
If you do not wish to use absolute layout, then it is best to uncomment/remove code relying on the library and re-do the form design using the new layout.
Can you try importing
import org.xml.sax.Attributes;
This is part of the JDK. If you can't find that, something is really wrong.
I suspect you need to add the libraries to your maven pom.xml file.
You should redirect all the lost .jar files by exiting netbeans, then reopening it. There should be a prompt asking you to help the IDE find the .jar files. So please do so. If you aren't able to find the jar file. Clean and build the individual packages. There a new directory called a dist directory will be created in the package directory. Now you can redirect them.
Above was not working for me so I tried below and its working:
Google "absolutelayout.jar download"
Download jar
Open NetBeans and Add this "AbsoluteLayout-RELEASE***.jar" file to your project Library folder.
now try to run the project/file
in my experience the problem was with a Jpanel with AbsoluteLayout, I put free-design and solved the problem

Categories

Resources