I am new to android programming.
I have got the Google native contact code and imported it in the eclipse IDE .
After importing there are errors in each and every Java file and errors are like, some classes are importing the other classes that is not in the project not even in android.jar.
So I have downloaded android-apps-4.4_r1.jar file and added it to the project(external jar). By doing this most of the errors have been removed but still there are many errors to remove.
e.g.: one class has been imported android.provider.ContactsContract.ContactCounts
and there is a class file in android.jar folder named android.provider.ContactsContract but I think there is not any variable ContactCounts in that file, so I have searched this file (android.provider.ContactsContract) in the Internet and there I found it so my question is how to replace that class file (exist in android.jar folder) with the new file that I have found it on the Internet or there is some other way to solve this problem?
Check this url for references
http://docs.oracle.com/javase/tutorial/deployment/jar/update.html.
jar uf jar-file input-file(s)
Here 'u' means update.
ContactCounts is hidden from the public. Notice the #hide attribute in the source code of the class.
Source code: ContactsContract
You cannot use the hidden classes without extensive work and you will be vulnerable to the code being removed, not present, or changed in future or previous versions of the Android API.
You could try to copy the source code for the hidden class and use the local version of it in your project.
That means:
Create a new file called ContactsContract.java in your project
Copy the contents from the file linked above
Rename the package to match your project
Import your local class where the file is used
Related
I want to use the API from Maps.Me. I've
downloaded the repository from github
extracted the files
copied the lib folder
created a libs folder as ...AndroidStudioProjects[MyApp]\app\libs
pasted the lib folder into the libs folder
The instructions on github say I should then "add the library project to [my] project". My problem is that all the advice I can find here and elsewhere online assumes that I will have a jar file which I will now see in Android Studio. I don't have a jar file and I can't see a libs folder anywhere in the Project tab on Android Studio.
(The libs folder that I have created contains the folders and files that I would expect to see in an Android Studio project folder, namely res and src folders and AndroidManifest.xml, build.gradle, build.xml and project.properties files)
What do I do next?
One thought is that I should import the downloaded library as a new project into Android Studio and then create a jar file from it. Would this work? Perhaps there is an easier way?
In case it helps anyone coming to this thread in future, I'll describe how I have worked around this issue.
As can be seen from the comments, I failed to import the library into my app in Android Studio, despite all the helpful guidance from CommonsWare. If I were more familiar with Android Studio, and Gradle specifically, I hope that I would have been able to succeed. However, I have followed a route which, for me with my limited experience of Android Studio, is more straightforward.
For each class in the downloaded repository I added a new Java class to my app with the same name.
I did not include one of the classes which included a dialog and relied on a layout and other resources, since I knew that I would not need this class
I copied all the code, except in each case for the package name, from each class in the depository and pasted it into the new classes.
I removed from the code that I did copy the one reference to the missing class
the result was code that worked exactly (so far as I know) as if I had imported the library.
Obviously, the result is inelegant, but for an app that is solely for my personal use it is good enough. It works.
I have an android project which requires to include a non-java resource file to included in the final package with Java class.
If you are using Eclipse, it is very easy, just put the non-Java resource file in the same package of Java classes, Eclipse will automatically copy the resource file to the destination.
I tried the same method in Android Studio, which uses Gradle for building, but it doesn't pack the resource file in the final Java class package. I have no control over how to read the resource file, it must use class.getResourceAsStream() to read the resource file.
Is there any way to pack resource file in Java package in the final product? Any suggestion is much appreciated.
First, Create a java resources folder.
Second, Create the same structure with a package name of a class.
for example, picture blow, you will have the same folder structure if you have a Tobee.class in a com.tobee package.
You can read a file in a Tobee class by calling a getResource or getResourceAsStream method.
getClass().getResourceAsStream("jar_properties");
Alright, I have solved the issue: pack everything in a jar including resource files then import this jar into the Android project.
This seems to be a common issue when exporting jars with Eclipse. Now, my context.
I'm attempting to write Java plugins to use in Unity applications. When I did a simple plugin with no external libraries (except the classes.jar so I can call a UnityPlayerActivity), it worked pretty well. "Now, let's use some utils libraries". So I wrote a plugin which uses Jackson libraries to parse and process JSON data, so I can serialize it to a Java object, or just pass RAW data, then build a Unity (C#) object.
I add the libraries directly from the file system to the 'libs' folder (copying the .jars, not linking them), add to build path, check every one in the Order and Export, clean and build, and export to JAR file (not runnable, but simple JAR file). Then, I add my new .jar to Unity Assets/Plugins/Android folder, then build my .apk. As soon as the game starts, I get the classic NoClassDefFoundError because of a constructer using a Jackson class. Checking the .jar contents, I find that Jackson libraries are, indeed, exported and within the 'libs' folder, but still it won't "find" it. The error will be thrown by the main thread, thus the application will crash.
I'm using ADT with API 17, so the libs folder must be named 'libs' (even Eclipse does create this folder when creating a new Android project), JRE 1.6 and Jackson libraries ver. 2.2.0. Already followed a lot of questions here, but none of their suggestions has worked for me.
Any pointers here? Has the Android API version anything to do here? Is there something I'm not doing?
Thanks in advance.
I'm quite new to Java, but as far as I can tell when you use an external JAR file it is dynamically linked. In other words, it stays independent - it is not merged into your library.
This was obvious in my case: The external library I used was Google Analytics. Its JAR file, libGoogleAnalyticsV2.jar, is 126 KB. After I added it to my libs directory and built my library I got an output JAR file of only 2 KB...
My solution was to copy the external library JAR file to Assets/Plugins/Android, together with the JAR file I created.
Hey I'm having a pretty basic problem importing classes into my Eclipse based Android app. I have included the class directory into the /src directory where I figured the classes would be easily included, but Eclipse is saying it "cannot resolve the classes".
One thing I noticed is that the project folder that I included and the subfolders are just regular folder and not package folder icons. Is that a problem? If so, how do I change them to packages? This is an external git repo, so I'd rather not do anything beyond just including them in my project.
Here are some pics of how I set up the project to help:
The Activity where the error is:
Here is the package structure in the project, and the package called "android-utils" where the files I'm trying to import live:
Here is how I'm importing the files:
Btw, these classes are just some utils and I'll be improving and adding to them during the development process.
Let me know if you need any in more info to help me get these files imported the right way. Thanks!
Did you try dragging the .java files from Windows Explorer directly onto the package in Eclipse you want to put the new classes into? It should then ask to copy or link to files.
As your folder contains only java files Add them as Jar File in your Buildpath project, and your problem will be solved.
Also your jar file you can put it under the /libs folder
see this link to lean how you create jar file
I am using the code of this answer, where as I have to add ITelephony.aidl to my project source, I did that.
But this aidl file not compiling. Is there any other step which are required?
First create a package in the src folder in your project named com.android.internal.telephony and within that package create a file and copy paste the interface ITelephony and save the file as ITelephony.aidl. When you compile you will get the .java file for the ITelephony in the gen folder.This is what I did and my issue got solved.
Hope this helps
If your aidl file is showing any error in eclipse then you should consider it and post the error here but if it is not showing any error you must clean your project and build it again. After this process you must go in "gen" folder and check either this file is compiled there and any class is exist with the same name of aidl file. If it is found, its mean aidl file is compiling properly.
Thanks and Regards,
Ali
Certin versions of Eclipse move the reference library folders for prjects.Either update eclipse, reinstall eclipse and the adt plug in or move the library within your eclipse folder.