I think the people who write the tutorials forget that the people reading them are new to the topic. We're supposed to learn about those by stepping through things, but if something goes wrong we don't know where to look for the error.
I have Windows 7 Pro, I have not attempted any eclipse development for android on this machine (though I use eclipse for other things). I downloaded the Android tutorial just now, installed it with defaults (I doubled the memory size from 2G to 4G on whatever component that was) and told it to start up after it had installed. "Help / About" says it's "Android Studio 1.3.1".
I followed the tutorial instructions for creating a new project, changing the names of the couple of files where it indicated. When I attempt to run it, the log file at the bottom of the AS window says:
Error retrieving parent for item: No resource found that matches the
given name 'android:TextAppearance.Material.Widge.Button.Inverse'.
Error:(2) Error retrieving parent for item: No resource found that
matches the given name 'android:Widget.Material.Button.Colored'.
On poking around, I seed that the "MyActivity.java" file is underlined in red, and there are three references in it to "R", also red. If I hover over any one, it says it cannot resolve that symbol.
I also found a file named "v23\values-v23.xml" that has red text for what look like a couple of android components; one of them is the following:
<style name="Base.Widget.AppCompat.Button.Colored" parent="android:Widget.Material.Button.Colored"/>
and the value for 'parent' is underlined in red. Since this looks like it indicates an error with something called "parent" and my runtime error message says "parent", it seems logical they're related.
But I don't know where to go from there. I vaguely remember an instruction to download an Android SDK, but thought that was included with Android Studio (can't imagine why it wouldn't be). It was called the "Android Studio SDK Bundle", I figured that included what was needed.
Other SO questions on the subject are evidently too old, saying to click on menu options that no longer exist, etc., or say things like "open the gradle file" and I can't find one, or "be sure your target project version is set to 11", and I don't have any idea what that is or where to find it.
Please be explicit about menus to use and options to click on; remember that, though I'm an experienced Java programmer, I've not used IntelliJ and I've not programmed on Android, so I don't know the names of things specific to either environment.
Daniel Nugent called this shot: at the bottom of the left-hand pane is an option called "Gradle Scripts". My first one was named build.gradle (Project: MyFirstApp), and my second build.gradle (Module: app). Double-clicked on the second one and changed "compileSdkVersion 22" to "compileSdkVersion 23", then attempted a rebuild which failed. The question Daniel Nugent referred to also mentions ensuring I have "Android M libraries" and points to a button on the Toolbar to start the SDK manager; that showed that an update "was available" for Android 5.1 (Lollipop). I couldn't figure out how to update from that window; I guessed at clicking on a link in that window (at the bottom) saying "Launch Standalone SDK Manager", and updated from there (which took a LONG time - 15-20 minutes).
Then the rebuild on Gradle succeeded and running the application (which took perhaps a minute or a minute and a half, longer than I expected) produced the expected window to pick a device, etc. The emulator then ran the "Hello, World" app as desired.
My thanks to all who responded; now if I can just figure out what's wrong with the debug driver for my Galaxy s5...
Related
I have an app which I am compiling against API level 21:
and then debug it on a real device with API level 23:
The problem is when I try debugging through the Android OS's own classes, I get 'Source code does not match the bytecode'. Why is this happening? The test device the app is running on is API level 23, and the source file being debugged is level 23 as well.
I am really confused. Can anyone explain why I am seeing this message and how I can fix it?
There's an open issue for this in Google's IssueTracker.
The potential solutions given in the issue (as of the date of this post) are:
Click Build -> Clean
Disable Instant Run, in Settings -> Build, Execution, Deployment
Here is my solution:
If you got more than one library version, this may help.
set a breakpoint on the lib source code
let the code run to the breakpoint
you will got these tips
click the arrow icon
you will get this
double click to select the correct lib (normally the highest version of the lib is correct)
I have clicked the "disable" button by mistake, you can enable it in the debugger setting
If you do not have the tips in the step 3, maybe you can check whether you have checked the setting options
You should use an Android emulator with the same api level as the compileSdkVersion.
In your case you should use Android emulator with api level 21.
If you use Gradle, it is probably a problem with Gradle caches. (Reference). Alas, even if you run
gradle --refresh-dependencies
, it is not refreshing really all dependencies. Some rubbish remains. (Reference).
So, the most sure (but drastic and long) variant is to clear all inside from the [user]/.gradle/caches. Or to find your problem project there and clear only its caches.
My app is compiled on API LEVEL 29, but debugging on real device on API LEVEL 28.I got the warning source code does not match the bytecode in AndroidStudio.I fixed it thought these steps:
Go to Preferences>Instant Run: uncheck the instant run
Go to Build>Clean Build
Re-RUN the app
Now, the debug runs normal.
These are the steps that worked for me (For both Mac and Windows):
Click on "File"
Click on "Invalidate Caches / Restart ..."
Choose: "Invalidate and Restart"
Note: It will take less than a minute for small projects, but since my project was big (approximately one million lines of code), it took 20 minutes.
I tried all the solution given here and none of them worked for me. In version 2019.1.3 I just clean & rebuild artifact and it worked; first do Build -> Build Artifacts... -> <select your artifact> -> Clean then click Build or Rebuild from same place.
Go to Project Settings > Artifacts. Select the artifact which has the problem. There is an option "Include in project build". This needs to be checked(enabled). For older versions of IntelliJ this option is "Make on build".
Probably this error message can have more than one cause, my case was not like the one from the OP, in my case this was due to a 3rd party library that required additional libraries.
For example: you manually add X.jar to your LIB, but this X.jar requires Z.jar to work.
It took me sometime to figure out, the message was not helping at all. I had to debug the app until I reached the crashing class, and in that class make sure that all imports were satisfied.
(Particualry: I added MercadoLibre-0.3.4.jar, which required commons-httpclient.jar)
Hope this helps!
This can also happen in case you have enabled ProGuard. In buildTypes set minifyEnabled false, shrinkResources false, useProguard false
I tried the solutions given here while working on an application that used Bluetooth Low Energy(BLE). I tried,
Clean Build
Disabled Instant Run
Invalidate Caches / Restart
all of these failed.
What I did was debug the points where I thought I was getting the warning, I still got the warning but the application was working fine. You can disregard the warning.
You can created AVD, select API Level equal your tagetApi andr compileApi, it works for me.
So I created an account just so I could help fix this problem that is plaguing a lot of people and where the fixes above aren't working.
If you get this error and nothing here helps. Try clicking the "Resume program play button" until the program finishes past the error. Then click in the console tab next to debug and read the red text.
I was getting that source code error even though my issue was trying to insert a value into a null Array.
Step 1 Click the resume button
Step 2 Click the console tab and read the red text
here is cause of why I got this error "source code does not match bytecode". My cause doesn't have anything to do with any API, compiler version..... It is caused by when inflate a layout view into a root view while I mistakenly initiate the inflator in else where (a chuck of "result handler" code that put on top of onCreate function of android app code). Somehow the debugger doesn't give me right hint of this (ex, inflator is not initialized or has instance) when breakpoint is set and stop here.
This happened to me when accidentally I have added the same library multiple times.
implementation 'androidx.appcompat:appcompat:1.1.0'
The above library was added multiple times.
If clean, rebuild, invalidate cache and restart etc. techniques are not working, then try deleting the previous APK and reinstalling the new APK.
Android Studio takes source version equal to Target Version in your application. Compilation performed with source version equal to above mentioned Compile Version. So, take care that in your project Compile Version == Target Version (adjust module's build.gradle file).
I had the same issue and found a solution. If you have a line flagged in red, it will give you this error, but if you un-flag all of the lines it will work normally.
by flagged I mean when you click on the left side where the line numbers are and it highlights the line.
If that is not clear here are pictures.
go from:
flagged line
to:
not flagged line
I am just starting to use Android Studio.
I have followed the steps through in the Studio. I chose "Basic Activity". The app loads, but there's nothing but empty directories there and it has no activity folder or anything to edit the layout with.
I checked it in the Windows explorer, and it just looks the same as in Android studio.
I've read this, this, this, this, this, this, and other ones, and have probably spent over an hour trying to figure out how to do this.
I've also re-tried creating the project at least 5 times, but I've had no success.
Edit: Here's what the app folder looks like:
Edit: Someone told me I should just create a new activity. Being an absolute new person, I didn't know how to do that, so I looked at this post. However, the post tells me that I need to go into the "New" menu, but I don't see "Activity" in here like the post asserted it would be.
In the following menu click the arrow and select "Project" (is better):
Then go to "name of your project folder" > "app" > "src" > "main" > "res".
I have no idea if this was what was causing it, but first I uninstalled then re-installed Android studio, deleted the old project, and created a new one.
It still didn't work, BUT I just noticed a little error log button.
You see, I named my application com.con.pfq. It wasn't liking the "con" part - said it's an invalid file name.
Sooo... I recreated the app as com.connoriscool.pfqmmobile. It liked that more.
No idea what's happening here, but that's the solution.
I have an app which I am compiling against API level 21:
and then debug it on a real device with API level 23:
The problem is when I try debugging through the Android OS's own classes, I get 'Source code does not match the bytecode'. Why is this happening? The test device the app is running on is API level 23, and the source file being debugged is level 23 as well.
I am really confused. Can anyone explain why I am seeing this message and how I can fix it?
There's an open issue for this in Google's IssueTracker.
The potential solutions given in the issue (as of the date of this post) are:
Click Build -> Clean
Disable Instant Run, in Settings -> Build, Execution, Deployment
Here is my solution:
If you got more than one library version, this may help.
set a breakpoint on the lib source code
let the code run to the breakpoint
you will got these tips
click the arrow icon
you will get this
double click to select the correct lib (normally the highest version of the lib is correct)
I have clicked the "disable" button by mistake, you can enable it in the debugger setting
If you do not have the tips in the step 3, maybe you can check whether you have checked the setting options
You should use an Android emulator with the same api level as the compileSdkVersion.
In your case you should use Android emulator with api level 21.
If you use Gradle, it is probably a problem with Gradle caches. (Reference). Alas, even if you run
gradle --refresh-dependencies
, it is not refreshing really all dependencies. Some rubbish remains. (Reference).
So, the most sure (but drastic and long) variant is to clear all inside from the [user]/.gradle/caches. Or to find your problem project there and clear only its caches.
My app is compiled on API LEVEL 29, but debugging on real device on API LEVEL 28.I got the warning source code does not match the bytecode in AndroidStudio.I fixed it thought these steps:
Go to Preferences>Instant Run: uncheck the instant run
Go to Build>Clean Build
Re-RUN the app
Now, the debug runs normal.
These are the steps that worked for me (For both Mac and Windows):
Click on "File"
Click on "Invalidate Caches / Restart ..."
Choose: "Invalidate and Restart"
Note: It will take less than a minute for small projects, but since my project was big (approximately one million lines of code), it took 20 minutes.
I tried all the solution given here and none of them worked for me. In version 2019.1.3 I just clean & rebuild artifact and it worked; first do Build -> Build Artifacts... -> <select your artifact> -> Clean then click Build or Rebuild from same place.
Go to Project Settings > Artifacts. Select the artifact which has the problem. There is an option "Include in project build". This needs to be checked(enabled). For older versions of IntelliJ this option is "Make on build".
Probably this error message can have more than one cause, my case was not like the one from the OP, in my case this was due to a 3rd party library that required additional libraries.
For example: you manually add X.jar to your LIB, but this X.jar requires Z.jar to work.
It took me sometime to figure out, the message was not helping at all. I had to debug the app until I reached the crashing class, and in that class make sure that all imports were satisfied.
(Particualry: I added MercadoLibre-0.3.4.jar, which required commons-httpclient.jar)
Hope this helps!
This can also happen in case you have enabled ProGuard. In buildTypes set minifyEnabled false, shrinkResources false, useProguard false
I tried the solutions given here while working on an application that used Bluetooth Low Energy(BLE). I tried,
Clean Build
Disabled Instant Run
Invalidate Caches / Restart
all of these failed.
What I did was debug the points where I thought I was getting the warning, I still got the warning but the application was working fine. You can disregard the warning.
You can created AVD, select API Level equal your tagetApi andr compileApi, it works for me.
So I created an account just so I could help fix this problem that is plaguing a lot of people and where the fixes above aren't working.
If you get this error and nothing here helps. Try clicking the "Resume program play button" until the program finishes past the error. Then click in the console tab next to debug and read the red text.
I was getting that source code error even though my issue was trying to insert a value into a null Array.
Step 1 Click the resume button
Step 2 Click the console tab and read the red text
here is cause of why I got this error "source code does not match bytecode". My cause doesn't have anything to do with any API, compiler version..... It is caused by when inflate a layout view into a root view while I mistakenly initiate the inflator in else where (a chuck of "result handler" code that put on top of onCreate function of android app code). Somehow the debugger doesn't give me right hint of this (ex, inflator is not initialized or has instance) when breakpoint is set and stop here.
This happened to me when accidentally I have added the same library multiple times.
implementation 'androidx.appcompat:appcompat:1.1.0'
The above library was added multiple times.
If clean, rebuild, invalidate cache and restart etc. techniques are not working, then try deleting the previous APK and reinstalling the new APK.
Android Studio takes source version equal to Target Version in your application. Compilation performed with source version equal to above mentioned Compile Version. So, take care that in your project Compile Version == Target Version (adjust module's build.gradle file).
I had the same issue and found a solution. If you have a line flagged in red, it will give you this error, but if you un-flag all of the lines it will work normally.
by flagged I mean when you click on the left side where the line numbers are and it highlights the line.
If that is not clear here are pictures.
go from:
flagged line
to:
not flagged line
I recently created a bug-free, fulling functioning android project. I even tested it on an android device, it worked fine.
I then closed eclipse and installed a few things from the SDK manager intended to speed up my emulator (intel x86 atom system image). After the downloads finished I opened eclipse and had errors on almost every line of my previously fine code.
It didn't recognize any of the android imports (hence the title). I couldn't open the android SDK manager because of:
"Location of the Android SDK Manager has not been set up in the preferences."
Then, after a bit more poking around a window popped up saying:
"Multiple errors have occurred. java.lang.NullPointerException".
The XML doesn't have any error warnings, but the graphical display window is blank and at the bottom it says:
"Eclipse is loading the SDK. new_page.xml will refresh automatically once the process is finished."
(its not loading anything, it has been that way for about an hour). I tried cleaning and rebuilding the project to no avail. I can't post pictures for some reason, my apologies. Some advice would be greatly appreciated! TLDR: I updated with the android SDKmanager and now nothing works!
All public classes within the android.os package are marked with the JavaDocs attribute #hide, which, when applied to a package, class, method or field, removes that node and all of its children from the documentation.
Thus the namespace is not available to be imported, as there's nothing in it.
See here, for example, another question about why the android.os.SystemProperties cannot be used in code (without Reflection).
Here's a link to the source indicating the use of the #hide attribute in the SystemProperties class: https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/os/SystemProperties.java#26
I encountered the same error the other day, actually same scenario and I just followed this guide and everything works again. http://developer.android.com/sdk/installing/installing-adt.html
I'm not getting the javadoc (I guess it's called) popup in Eclipse which gives details about the Java/Android method I'm currently hovered over. For instance, if I type Log.d and hit CTRL+SPACE there is usually a popup which shows some info about the Log.d method. This isn't happening. Any ideas how to fix it? I recently upgraded to jdk1.7.0_06 and I think the Java docs got smoked somehow. I followed a few different threads on S.O. to try and fix it but still nothing.
I've downloaded jdk-7u6-apidocs.zip from oracle and tried loading it in Window > Preferences > Java > Installed JREs > [select jre] Edit > JavaDoc location but when I try to validate, a popup says: "Location might be invalid. Files 'package-list' and 'index.html' that are typically available at the root of the documentation created by the Javadoc tool have not been found"
So then, in the same dialog above, I ticked 'Javadoc URL' and entered "http://download.oracle.com/javase/7/docs/api/". It validates OK, but I still don't have documentation for Log.d and others.
So, I guess how do I get the documentation popup back, and is this a java issue or android SDK issue?
Instead of pointing to JRE, you can try to point to JDK. In that way source is also be linked
Nevermind. Follow alphaRiv's solution here: JavaDoc not working in Android project
My path was borked so pointed it to my android-sdk-linux/docs/reference directory and all's well.