I use AndroidAnnotations, and since a couple of days, Eclipse sometimes (not always) fails to compile code that uses classes generated by AndroidAnnotations (pre-compile generated code):
My example is:
My project has MainActivity, AndroidAnnotations creates an extended class MainActivity_ under .apt_generated.
Elsewhere in the DetailActivity, my code has a reference to MainActivity_:
My solution so far was to remove the code, compile, then add the code back. However, this is far from elegant. It also is quite annoying and time-consuming.
Am I missing some setting?
Does the order in the "Order and Export" page have any influence? I've tried to move the .apt_generated directory up and down, with no positive effect.
I was thinking that this is the same concept used by Android's resource class R. I never had any issues with code that use resources failing to compile.
When does that happen?
When you open Eclipse?
When you open a project previously closed?
When you do a project > clean?
This problem looks like a bug in Eclipse. It looks like sometimes it compiles a class, then run the annotation processor, then doesn't update / recompile the classes that had missing symbols.
A simple tricks that seems to do the job: go to the properties of the project, change the name of the annotation processing folder from .apt_generated to something else (and then back to .apt_generated), and accept the rebuild. This seems to trigger a build in the right order, and reset everything right.
Note that AndroidAnnotations uses annotation processing, which is a standard java 6 concept. It's different from the Android R class, which isn't linked to any java standard.
Does that help?
As per comments above from piwai the anwser is:
Eclipse 3.5+ - Annotation processor: Generated classes cannot be imported
Related
I need your help, (I searched the questions, but I do not understand though the answers are positive) What should insert code? (The answer comes that I send the code of appcompatactivity. But I do not understand)
I'm working with android NDK but send me the error .. This is my code
C:\Users\Eduu\AndroidStudioProjects\NDKSample2\app\src\main>javah -d jni classpath C:\Users\Eduu\AppData\Local\Android\sdk\platforms\android-19\android.jar;..\..\build\intermediates\classes\debug com.example.eduu.ndksample2.MainActivity
work: Android Studio
When you create a new app, Eclipse gives you a copy of the compatibility library. (One can only guess if you are using Eclipse, but I do.) The purpose of this library is to implement fragments and other post-3.0 stuff on 2.x devices. You are given this library only if you specify a 2.x target when you create the project. In one of my workspaces, I have 24 copies of the library, ranging from appcompat_v7 to appcompat_v7_24. Each one is located on the same directory level as the corresponding project, that is, in the same parent folder. It is easy to guess which copy corresponds to the latest project, but if you don't know for sure that the project is the latest one, you have to search the config files.
If you put your project under version control and forget about this dependency, you get an error in the copy retrieved from the version control. Fixing it is a tedious task, Eclipse is no lucid coding. You will have to manually specify the dependency in several places. One possible approach is to create a new project and move the source to it (note that you can move the version control directory, like .hg or .git, and restore the source, if that does not sound too untrivial for you), another one is to create a new project and use its compatibility library.
There are several ways that Andorid aka-native code (Java code) could be integrated into Xamarin project. Official ways are listed in this article.
We are trying to use a Java Library Binding approach discribed in the article.
Our test andoid library is published on Github for this question specifically.
We've created it in Android Developer tools setting it as Java Android Library. It is built in Eclipse into a .jar format that tutorial on Xamarin site assumes to be sufficient.
If we are trying to bind .jar into our project in Visual Studio, the Object Explorer will show us the binding asseblie's namespace, but in code, even though the assembly is referenced, we can't access the methods and classes in the namespace, decleared in our test java android lib..
On the other hand, when we take almost any .jar, which is an android library on the internet (for example this one), we can bind it and access it's methods without a problem.
Please compare two .jar and if possible, let me know what is wrong with our test android library on github, that causes our namespace to be unavailable from code.
I read the same Binding a Java Library article you did, went through the instructions, and had no build errors. When I attempted to use the classes from my jar file, intellisense was not recognizing anything. Then I read the follow-on article on API Metadata Reference. This got me thinking that perhaps I should try editing the Transforms/Metadata.xml file. After editing that briefly to include a rename of the package, Visual studio allowed (after a compile) a reference to a class from the jar file. I then attempted to call a method from the class, and again, got another compiler error. So, I went back into the Metadata.xml file and added an entry to rename the method in question. I edited my code to call the renamed method, and Visual Studio compiled fine. I integrated this call into a unit test case, and it passed!
From my reading, it didn't seem necessary to edit the Metadata.xml file, but at least in my experience it seemed necessary. It uses XPATH on the obj/Release/api.xml file (as stated in API Metadata Reference). From that article there were examples for renaming both package & method names, so it wasn't much work for me to insert into my Metadata.xml file. In addition, I downloaded the OsmBindingDroidExample from the Binding a Java Library article and checked out their Metadata.xml file as well.
Here's my XML for reference as well:
<metadata>
<attr path="/api/package[#name='com.abc.def']" name="managedName">MyRenamedPackage</attr>
<attr path="/api/package[#name='com.abc.def']/class[#name='MyClass']/method[#name='originalJavaMethod']" name="managedName">RenamedDotNetMethod</attr>
</metadata>
So, now in my .NET code, I could write:
MyRenamedPackage.MyClass.RenamedDotNetMethod(...);
Hope this helps!
EDIT:
I've gotten a bit more familiar with the Xamarin toolkit, and have an update to make using this easier.
In order to limit the involvement of code that needs to interact with the jar methods, Xamarin allows you to create C# classes in the Additions folder. So, I created a wrapper class that exposes the methods in a managed C# class that other projects can access. Since it's C# there's no complaints from Visual Studio.
Here's what a wrapper class would look like going with my earlier example (obviously you'd pick a name more meaningful to the task at hand):
public class InovcationWrapper
{
public static void InvokeMethod(...)
{
MyRenamedPackage.MyClass.RenamedDotNetMethod(...);
}
}
Then in your project code, you'd have full intellisense if you just call your wrapper class:
InvocationWrapper.InvokeMethod(...);
This makes it much easier to work with and limits the amount of red squiggles to be ignored in your code. Hope this helps!
I've been working on getting unit testing to work with a custom Android library. I've followed the first suggestion from this Android developer guide and created an Android app project that depends on the library (via Properties->Android->Library->Add...) as liaison to the actual testing project.
All seemed to work fine, but then I encountered my first run-time-exception in one of my test cases. When I wanted to fix the code in my library, I found, that double-clicking any item in the JUnit test panel would open a .class file, instead of the corresponding .java file. So editing the code is not possible, until I've crawled though the package hierarchy and grabbed the .java file manually.
Also, the debugger/test-runner is happily ignoring any breakpoints in the library. Is there a way to make the test project realize, that the code for the library is right there in the workspace? Not having the abilities to debug using breakpoints and jumping from a stack trace into the code are big productivity bummers.
Addendum: After leaving Eclipse and starting another session, now breakpoints seem to be respected. However, the debug-perspective will open the .class files instead of the corresponding .java files.
I'm just getting started in Android development, and use Netbeans with NBAndroid and SDK 17.
I'd like to use the same Java source code in my Java and Android app.
http://developer.android.com/guide/developing/projects/projects-eclipse.html says how to do it in Eclipse (although it is sketchy on the .JAR connection thing), but I can't seem to make it work in NB.
Based on that link, My understanding is that the correct setup for the Android app is an Android Application project which references an Android Library project which in turn references a .JAR library produced by a Java Library project. I could then also have a Java Application project referring to the same Java Library project.
So, I've set up this project structure... I have an AndroidApp project which is a basic HelloAndroid Activity in a com.ex package. This project includes an AndroidLib library project in the Libraries folder. I also have a LibClass.java file which defines a simple LibClass class which has one function getText() that just returns a String to be displayed. The MainActivity in the AndroidApp calls this to get the String to output.
When I put LibClass.java directly into the AndroidLib project, everything is fine.
But what I want to do is to share the source code with Java.
So I want to move the LibClass.java into the JavaLib library, whose .JAR file is included in the AndroidLib project. However, when I tried that, I get an error in the MainActivity class, complaining it can't find LibClass. Looking at the Projects window, I can see LibClass.class inside the com.ex package in the JavaLib.jar in the Libraries folder of the AndroidLib project. And AndroidLib is visible in the Libraries folder of the AndroidApp project, but it doesn't show any packages or other contents there.
So I feel like I'm just one step away from making this work. Do I need to do something with one or other of the AndroidManifest files perhaps? Or do something with the build.xml files? Or am I on the wrong track altogether?
I'd be really grateful if someone could post a how-to for this.
I'm trying something similar; I've got Java EE projects, built using Eclipse, and I'm trying to utilize some of that code from my Android projects. This should give me a shared codebase rather than a bunch of confusing SVN externals which I've had to endure before.
Rather than creating JAR files I've found that working with the source and building for the platform works best (well, it has been working but I've got a problem with it at the moment). So, what I'm doing is:
c:\MySvnFolderStructure\MyJavaProjectFolder\src\ (and then all the source under that)
c:\MySvnFolderStructure\MyJavaProjectFolder\android\ (and all the Eclipse Android project gubbins)
c:\MySvnFolderStructure\MyJavaProjectFolder\jee\ (and all the Eclipse JEE project gubbins)
The Android and Java EE projects do not have their own src folders, they both link to the src folder in their parent folder. What this means is that each of the Java implementations is building its own byte code version from the source, and using its own external libraries (like the Apache HTTP ones, for example).
Naturally they can't share stuff like awt (as mentioned in another post), but there's plenty of stuff that does cross-over especially if it's core Java classes that are being used.
Also, it's proving a bit tricky writing JUnit tests as there needs to be some duplication of the test code at the moment because the Android ones need extra instrumentation, but I'm working on it.
Also, see this post about relative paths in Eclipse, which means the folders can be checked-out to different places on different machines (like we all do with our version control check-outs) and still be shared.
if I understand your situation correct, you are trying to use a custom java library for both your android and java applications.
For this scenario, you can build the java library first. Instead of adding the java library jar as android library, you can drop the jar directly inside the libs folder of android project and add it to android project's build path.
If you are using ANT scripts for building the java library jar , you can consider adding the source files also as part of jar. This will help you get code assistance when you develop the android part. But this part is purely optional.
The problem is that the Java platform in Android is different from the JDK platform.
In particular, the .JAR library CANNOT refer to anything that is not icluded in the Android platform. An example of things you can't refer to is java.awt.* (except you can have java.awt.fonts).
There is also a difference between JDK String and Android String -- Android does not implement the isEmpty() method.
I have two android projects, ProjA requires ProjB (in Eclipse Properties > Java Build Path > Projects > Add > ProjB). Every thing compiles ok in Eclipse, but when I run ProjA I get an error:
Could not find method XXX, referenced
from method YYY.
Where XXX - is the method from ProjB.
How can I fix the settings?
I have a similar problem when using external jar (in my case openCSV).
The reason I had a problem was due to a change in ADT 17 (or above).
What I needed to do to resolve the problem was
In Eclipse go to Properties -> Java build path -> Order and export.
Mark my jar.
Move jar to top of the list.
The solution was found
in the following page which reference to a very good article.
Importing Class from External Jar, Android
you can try the above link..
I suggest taking care of this "android only support 1.6 and not 1.7" in your library jar
Combine the two projects into one.
Or, have ProjB build a JAR file that ProjA includes.
Or, turn ProjB into a remote Service, with the method in question exposed via AIDL, and have ProjA bind to that service to use the method.
You may want to look at your design, if you don't want to go with the answer by CommonsWare.
For example, you could call the second project from the first by using Intents, for example.
If there is code that is common to the two projects then you may want to pull that into a new project where you can include the files directly into both projects, but if the two are supposed to work together there are different ways in Android to allow Activities to call each other, or to pass information, and you may want to look at those.
I've experienced this problem with the new Android Gradle build system, I fixed it by running gradle clean and then building and installing again. Build systems are complex beasts and Google still has yet to solve the dependency problem perfectly.