How to find easily the source of an android class - android

I know I can access android source code from https://android.googlesource.com, but it's hard to select the right git repo if I only know the package and the name of an android class.
Isn't there a way to locate a file in https://android.googlesource.com?

Most things you'll want to see can be found under the frameworks/base repo.
This includes pretty much all the public and private API classes that make up the Android Java framework.
If you want to be able to browse the source from within Eclipse, you can follow this guide: http://blog.michael-forster.de/2008/12/view-android-source-code-in-eclipse.html
Finally, the Android SDK Reference Search extension for Chrome lets you browse the public API by typing ad into the URL bar, and it adds a convenient "view source" link to each Javadoc page.

In my opinion today the best way to look into android sources is the github repository :
https://github.com/android/
Public java classes can be found here https://github.com/android/platform_frameworks_base/tree/master/core/java/android
Internal package is here https://github.com/android/platform_frameworks_base/tree/master/core/java/com/android/internal
Resources are here https://github.com/android/platform_frameworks_base/tree/master/core/res/res
Support library https://github.com/android/platform_frameworks_support

Since 2011 the source code can be downloaded with the SDK Manager (Window > Android SDK Manager)
Install package "Sources for Android SDK"
Open Properties of android.jar, which you can find in the package explorer below the Android library
In "Java Source Attachment", select android/sdk/sources as external folder
Edit: Eclipse seems to regularly scan the external folder for updates. If this annoys you, you can zip the folder into a .jar and then tell Eclipse to look in that jar for the sources. Eclipse will then no longer scan for changes.

There is an issue raised against Android project for a single .jar file containing the Java sources.
The issue has been declined but the comments are a good source of methods to access the source in Eclipse.

also, this is a very good tutorial on how to get the source in eclipse, without having to mess with any of the repos or anything, it includes zip files of the the source (which might be out of date)

You can search for any Android class through https://cs.android.com easily.

Related

Android Studio ClassNotFoundException: com.mysql.jdbc.Driver after adding module

The error I am getting is java.lang.ClassNotFoundException: com.mysql.jdbc.Driver even though I have already added the .jar file by going to file -> project structure -> import .JAR Package. What could be the issue here? Image of module inside project structure:
Try putting jar file in your lib directory, then re-starting tomcat...
problem is Class.forName("com.mysql.jdbc.Driver"); it tries to load the driver, but it is not getting it, this is the reason you are getting java.lang.ClassNotFoundException.
check that your jarfile should be in class path
I had a TON of trouble with this for some reason. It is mentioned elsewhere that only 3.017 driver works, and since I made such detailed instructions I figured I'd share them. (My initial purpose was to give steps to reproduce error that I could use to ask a question here and elsewhere. No, I can't begin to guess why I had so much trouble now looking back)
To: Get JDBC Driver in Android app
New Android Project - AndroidJDBCTest, Target Android4.03, minimum
sdk 8 (Android 2.2), package name “com.test.AndroidJDBCTest”
Right click on project, new folder “libs”
Download Mysql JDBC Driver from here and extract it to your
filesystem.
Browse to the root directory after extracting and drag and drop the
jar mysql-connector-java-3.0.17-ga-bin.jar into /libs in your project
in project explorer inside Eclipse., using the default “copy” setting
for the drag and drop.
Right click on the Eclipse Project, Build Path-Configure Build Path,
Add JAR under libraries tab - Browse to /AndroidJDBCTest/libs and the
jar file and click ok
NOTE: It shows up now under “Referenced Libraries” node (if Eclipse is
set to show it)
Add code from here to the end of onCreate() - basically
Class.forName("com.mysql.jdbc.Driver").newInstance();
Attach Honeycomb device such as Motorola Xoom family Edition and run
Why are you trying to access MySQL DB from Android native? First it might work but it is not recomended. You can do it easily with PHP and JSON responses.
Check those:
http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql
http://www.tutorialspoint.com/android/android_php_mysql.htm
http://sampleprogramz.com/android/mysqldb.php
You can also download my project with HttpURLConnection since org.apache library has been deprecated.

Android Exclamatory red mark

I'm very new to Android. Whenever I create a new project using a new workspace, I get an exclamatory red mark in Eclipse in my project and an error at Appcompat. I searched here for an answer, but no answer was what I was looking for, so I just asked this. When I create a workspace at DDMS it displays this:
Sending Tracking request failed!
At Android, after I create a new project
WARNING: unable to write jarlist cache file here, src file, layout file not available.
I've searched a lot and found no solution.
OK, first thing first. Eclipse is no longer supported by Google. The only official IDE for Android Development is Android Studio Download Page.
Here is the announcement of Eclipse support ending
Over the past few years, our team has focused on improving the development experience for building Android apps with Android Studio. Since the launch of Android Studio, we have been impressed with the excitement and positive feedback. As the official Android IDE, Android Studio gives you access to a powerful and comprehensive suite of tools to evolve your app across Android platforms, whether it's on the phone, wrist, car or TV.
To that end and to focus all of our efforts on making Android Studio better and faster, we are ending development and official support for the Android Developer Tools (ADT) in Eclipse at the end of the year. This specifically includes the Eclipse ADT plugin and Android Ant build system.
Please note that the number of people using Eclipse to develop Android apps are going down. You will get less and less support even on Stackoverflow as time goes by. Overall, it is better to just make the switch while you are just starting.
Check on the first link, you will see some amazing documentation in the Android Studio IDE
If you 100% required to use Eclipse...
OK, so you have a job that requires Eclipse or there is some other reason, then check out this documentation by Eclipse.
Also, here is a list of all the different icons that can be displayed by Eclipse (credit for the icon list).
Build path problems are sometimes easy to miss among other problems in a project. The Package Explorer and Project Explorer views now show a new decorator on Java projects and working sets that contain build path errors:
The concrete errors can be seen in the Problems view, and if you open the view menu and select Group By > Java Problem Type, they all show up in the Build Path category:
Please refer this link too here
If you go to appcompat_v7/bin folder, you'll see that file "jarlist.cache" doesn´t appear or is unsynchronized. You need to
refresh the appcompat_v7 folder, only press F5 over that folder.
The appcompat_v7 folder is added because you use an action bar
component.
Aah. To avoid a new appcompat_v7_XX folder when you are creating a new
project, choose a LEVEL API 14 as Minimun Required SDK. After you must
modifier the AndroidManifest.xml and put the level that you need.
change it
android:targetSdkVersion="19" />
Delete all appcompat_v7_XX. It is a bug.
With appcompat_v7, You will see that Eclipse creates two XML files:
Activity_main.xml and fragment_main.xml. If you want to have an option
to create a project in the old way only with activity_main.xml, do
that:
Make a copy of the folder "BlanckActivity" located in this path:
\sdk\tools\templates\activities of an ADT previous version.
Rename the folder as “BlankActivityNoFragment”, then edit the field
name of the file "template.xml" with a notepad as
name=”BlankActivityNoFragment”
Copy the new folder in the same path of the new Eclipse
IDE:sdk/tools/templates/activities
Now you´ll see the new template when you go to create a new project.
Remember to choose as Minimum Required SDK an API 14
If you don't want the support of appcompat library then just remove it from your project by following steps :
Right click on project
Select properties
In dialog select android on left side
In dialog check library section
Remove appcompat library by selecting it and press remove
Extends your MainActivity.java with Activity
You can run your project successfully.
If you want the support of appcompat then follow this steps :
download the latest appcompat using Sdk Manager
import appcompat project in your eclipse
add it as a library project
extend your MainActivity with AppCompatActivity.
If you're getting any problem with app_compact library... This is the solution
Hopefully it will work....
According to the documentation
Decorates Java projects and working sets that contain build path
errors
There can be several reasons. Most of the times it may be some of the below reasons ,
You have deleted some of the .jar files from your /lib folder
You have added new .jar files
you have added new .jar files which may be conflict with others
So what to do is we have to resolve those missing / updating / newly_added jar files.
right click on the project and go to properties
Select Java Build Path
go to the Libraries tab
Remove the references of the jar files which you have removed already. There will be a red mark near them so you can identify them easily.
Add the references to the newly added .jar files by using Add JARs Refresh the project
This will solve the problem if it's because one of the above reasons.
Still Facing problem ??Try this:
Go to Windows -> Preferences -> Android -> Build and uncheck "Skip packaging and dexing until export or launch" then restart Eclipse.

Why do I get a source file not found error in the Android class file editor?

I am developing an Android application. Are there problems in my code, or is my source file really missing?
You are trying to view a file that has been compiled. These files only have the bytecode in them, the language that the device "understands".
If you want to see the source code for the android java files you must make sure to download the source via the sdk manager in eclipse. Then you can attach that source in eclipse so that you will see it instead of what you're seeing now, which is the bytecode. To attach your source, just click the attach source button and navigate to your sdk folder and there will be a souces folder. From there you can choose which version sdk to attach. Good luck!

Android InApp Purchase Example

I am facing the issue in building InApp Purchase Example App give in SDK.
It's showing error in IMarketBillingService.aidl because its showing like disabled file.
and the other java files importing this file shows error that
import com.android.vending.billing.IMarketBillingService cannot be resolved
Can any one solve this problem or give soemalternate solution for this InApp Billing i need good example for this.
I had a similar problem when trying to integrate the components from the example into my software. The source of the issue for me was that the code I was modifying was an Android library resource to the main project, and somehow the sources in the build path had gotten mixed up.
The solution for me was to (in Eclipse) right-click the project, Build Path, and Configure Build Path. Choose the sources tab at the top, and verify there aren't duplicate sources there, perhaps under different names. If there are, you're going to have to do some fiddling and figure out which ones belong.
I'm not sure how it gets into this situation; it was a long day...
Sorry for the ambiguous answer but I hope it helps anyone in this pickle.
With IDE android studio:
Step1: right-click app folder and choose new/folder/AIDL Folder
Step2: right-click aidl folder and choose new/package, make name is com.android.vending.billing
Step3: Copy IInAppBillingService.aidl to package com.android.vending.billing
Step3: Clean and Rebuild
==> It will work!.

How to attach Android Source to Eclipse

I've previously had success attaching the Android Source to Eclipse by following Finn Johnsen's instructions here.
However this approach seems to have stopped working:
samuel-josephs-computer-4:android-sources samueljoseph$ git checkout origin/froyo-release
Previous HEAD position was 1de4a2c... am 62619392: Merge "Fix leak when keylock is recreated."
HEAD is now at adba66b... This class no longer exists.
There was a more recent blog here which had some pre-organized source for Eclair, but nothing since.
There are also some StackOverflow posts from 2008 (older than both the above), e.g.
https://stackoverflow.com/questions/3182904/attaching-java-source-to-android-projects-in-eclipse.
What is the current guidance for accomplishing this?
There is a updated guide. So, you don't need to install an eclipse plugin for this.
Here is the link
Snip from above Link:
follow below steps if you already have downloaded Android sources
Head into eclipse, and press F3 over some android source you're missing, like Activity. And get this pesky window, which we all hate:
Click Attach Source, choose External Folder, and choose the core/java in the base folder.
There is an Eclipse plugin called Android Sources that installs the sources up through Gingerbread. I haven't tried it recently.
For Android 4+ here's a tutorial for attaching sources to eclipse.
EDIT:
First download the source and javadoc from sdk manager.
Goto Your_Project>>Android XXX, Right-Click on android.jar and select Properties.
Point the sources path as Java Source Attachment>>Location Path by clicking on External Folder
Point the reference path as Javadoc Location>>Javadoc Location Path by clicking on Browse
Now you can browse sources like this:
Here's a tutorial:
Make sure you have installed/downloaded the Android source for the appropriate Android SDK API version.
1.1 Check the API version you have specified in Eclipse for Android/Project Build target:
Open project Properties/Java Build Path and click the "Link Source..." button on the Source tab:
Point to where you have installed the Android SDK, expand the "sources" folder, select the appropriate source API version (and click "OK"):
Next...:
Important step is to exclude the whole linked source from building. Otherwise we could have some duplicate source errors plus who wants to build the whole Android source when we have jars already! So, click "Add...", type in *, click "OK" (and then "Finish"):
Verify everything is configured correctly:
Desired result -- linked platform source w/o side effects:
I hope this helped :)
The best way is as below.
Update Android SDK Manager, including source of the version you need.
click on Any class like activity, if source is properly attached, it will open the Activity class.
If it is not opening up, then click on the attach source and can give source path as above.
Source path will be like android-sdk-windows\sources\android-17
This will help you to add source for android SDK
You can do it this way .... hover or copy paste any class_name which is provided from android , just press F3 you will find a Attach_a_source tag there , click in it & here browse your android-sdk folder
and from it just pick source folder because inside it , every android files resides .

Categories

Resources