My Android Project was perfectly building and running. After updating Android Studio to v3.5.2 and also to latest gradle build version the build is failing without having done any changes to the code.
The problem seems to be related to Binding. The following error pops up:
> Task :app:compileDebugJavaWithJavac
C:\App\MyApp\app\build\generated\data_binding_base_class_source_out\debug\dataBindingGenBaseClassesDebug\out\com\project\databinding\LayoutBinding.java:13: error: cannot find symbol
import com.project.ViewModel;
^
symbol: class ViewModel
location: package com.hometech
C:\App\MyApp\app\build\generated\data_binding_base_class_source_out\debug\dataBindingGenBaseClassesDebug\out\com\project\databinding\LayoutBinding.java:19: error: package ViewModel does not exist
protected ViewModel.My_ViewModel mViewModel;
^
C:\App\MyApp\app\build\generated\data_binding_base_class_source_out\debug\dataBindingGenBaseClassesDebug\out\com\project\databinding\LayoutBinding.java:25: error: package ViewModel does not exist
public abstract void setViewModel(#Nullable ViewModel.My_ViewModel ViewModel);
^
C:\App\MyApp\app\build\generated\data_binding_base_class_source_out\debug\dataBindingGenBaseClassesDebug\out\com\project\databinding\LayoutBinding.java:28: error: package ViewModel does not exist
public ViewModel.My_ViewModel getViewModel() {
The related XML layout resource file that causes the problem looks like this:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="ViewModel"
type="com.project.ViewModel.My_ViewModel" />
</data>
<LinearLayout android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</layout>
The entire build runs successful if the layout resource file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
</data>
<LinearLayout android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</layout>
But as soon as I add the <variable ... /> part the build fails with the mentioned error messages.
(The 'ViewModel' package and the related ViewModel of course exists!)
I am super desperate about this. All the Android Binding stuff has often problems especially after updating but this time I simply do not find and fix and I tried a lot!
I appreciate any help, thanks!
I found the solution myself.
One of the error messages sais "package ViewModel does not exist".
Well, the package definitly exists and its also possible to access it from within classes.
As mentioned in my post I was able to build exactly the same project before updating Android Studio and gradle build to version 3.5.2.
I changed the naming of the package "ViewModel" to "viewmodel" and the build is finally successful again.
Also the expression "Viewmodel" was working, but only twice, the third time I tried to build the project like that failed again. A really strange behaviour of Android Studio!
So obviously something was changed in the newest Android Studio version that prevents using such a wording!
By the way, all other packages are also in camelcase like it was for "ViewModel" and they are not causing any trouble.
Teaching myself Java, still very new. Last night I learned how to import this library into my project in Android Studio. But now I'm confused as to how to actually start using it.
I know that Java works with classes and that supposedly a library is just a collection of classes (and probably others things too...) that you can begin using once you import it. But the author of this library told me to just use this:
BackgroundMail bm = new BackgroundMail(context);
bm.setGmailUserName("sendername#gmail.com");
bm.setGmailPassword("sender_email_password");
bm.setMailTo("receiver#gmail.com");
bm.setFormSubject("Subject");
bm.setFormBody("Body");
bm.send();
But when I try to put that into another one of my classes, I get red errors all over the place. So then I tried to create a Java class within my app's files and I still got red errors. Could someone kindly help me, a total beginner, get started here? I'd like to use this library to send an email in the background of my app.
To import the library:
I followed this answer: https://stackoverflow.com/a/35369267/5241266 and used Approach 2.
MainActivity.Java: this is where I put the import code.
package moviehelper.moviesfree;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.creativityapps.gmailbackgroundlibrary.BackgroundMail;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
For now, I have not added the block of code that the author told me to use (see above).
The Gradle Console error:
I get the following error when doing Build -> Make Project:
error: package com.creativityapps.gmailbackgroundlibrary does not exist
import com.creativityapps.gmailbackgroundlibrary.BackgroundMail;
My project tree: I think there might be some problem with this structure. It looks like the library was added as its own project? Although I'm not sure.
If you don't want to use the JitPack approach as documented in the instructions, then look at the settings.gradle file in the Github example.
It includes both modules (app and the library).
Then, once that is setup, you can compile project(:libraryName) in the app/build.gradle file's dependencies section. Again, see the Github sample for the syntax.
With those two steps (plus one to download the library), it should be importable within the app code.
Assuming you followed along with the other steps on the readme, at the top of your code you need to tell the source file to import the classes:
import com.creativityapps.gmailbackgroundlibrary.BackgroundMail;
public class MainActivity extends AppCompatActivity {
[your code]
}
I would also recommend looking through the sample code included in the github project
You are doing some wrong steps friend. You can follow this
Find your gradle file with name buid.gradle (Project: [ YOUR_PROJECT_NAME ] )
Then find and add this line
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
You are done 50% now. Now press SHIFT+CTRL+ALT+S and wait for a window.
On the Window, select DEPENDENCY TAB on top.
Click on + BUTTON at top right. Click on Library Dependency.
Now paste com.github.yesidlazaro:GmailBackground:1.2.0 there.
Click on OK and exit the window. Gradle recompiles.
Now simply put your code, If RED syntax error showing, Click at the code where error is showing and when a BLUE pop comes, Press ALT+ENTER.
Everything done..!
I started learning the Android SDK and I have a problem.
I launched the studio and the android screen didn't show up (YES, I know where the preview tool bar and how to switch).
Quote:
"Rendering Problems The following classes could not be found:
- android.support.v7.internal.widget.ActionBarOverlayLayout (Fix Build Path, Edit XML, Create Class)
Tip: Try to build the project."
*Sometimes there is another rendering problem and this is showed :
"Rendering Problems The following classes could not be instantiated: - android.support.v7.internal.widget.ActionBarOverlayLayout (Open Class, Show Exception, Clear Cache)"
I'm pretty sure its the "appcompat_v7", which is automatically generated in eclipse when setting up an android project. It imports unnecessary features and causes a bunch of build errors.
Delete "appcompat_v7" folder
go to your MainActivity
Delete the import "android.support.v7.app.ActionBarActivity";
change "MainActivity extends ActionBarActivity" to "MainActivity extends Activity"
add import android.app.Activity;
add import android.os.Bundle;
add import android.view.Menu;
add import android.view.MenuItem;
go to res folder and then go to your values folder...delete styles.xml
delete values-v11 folder
delete values-v14 folder
go to menu folder, and click on main.xml...go to "item" tag and delete app:showAsAction="never"
go to AndroidManifest.xml...go to "application" tag...delete android:theme="#style/AppTheme"
go to project at the top...clean and build...you should have no more errors.
When I first created my test project I told it that my package was com.example.test. Now, i've renamed the source package to com.imcool.android, and I also updated the package in my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.imcool.android"
android:versionCode="1"
android:versionName="1.0" >
After a full clean, Android asks me if I want to update my launch configurations, I click yes. I try and run an android unit test and I get this error:
Test run failed: Unable to find instrumentation info for: ComponentInfo{com.imcool.android/android.test.InstrumentationTestRunner}
If I change the package in my manifest back to com.example.test it works, even though my actual source package name is still com.imcool.android.
Whats the deal?
it's not android that has asked you . it's eclipse . :)
anyway, just go to the run-configuarations and delete all of the items that aren't needed anymore , and do the run again . this way it will forget about the previous configuration and will use only those that you ask of it.
This question already has answers here:
R cannot be resolved - Android error
(108 answers)
Closed 10 years ago.
So I copied this tutorial example thing right from Google's android site and I ma getting an error that R.id cannot be resolved.
Here is my Java file
package com.TestApp.HelloWebView;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class HelloWebView extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.google.com");
}
}
Here is my res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<WebView android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
You have to import your R class
import com.TestApp.HelloWebView.R;
Also as Demand posted you have to use a namespace for your layout.
?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
I had the same problem when I updated my Android SDK. Suddenly new projects could not generate the R.java file.
importing my R.java didn't help because it wasn't generated
cleaning and building the project didn't help either -- the /gen folder was still empty.
I found that after the upgrade, the adb server didn't start up properly. So a manually started it:
$ cd $ANDROID_SDK/platform-tools
$ adb start-server
Then I restarted Eclipse and did a clean/build on the project, which generated the R.java file.
If using Eclipse, run a clean build (Project/Clean...); this can often clear issues with the resources not being compiled correctly.
Did you try any of the solutions listed here?
R cannot be resolved - Android error
Also, look for your R.java file. Are there any errors with it?
I had this problem too. I can't say a solution in general, but you can make a new workplace and copy the hardcode. In the future never click on clean or build, instead save or start eclipse again.
Go in your main.xml file, delete a char and rewrite it. That will generate the R file again.
On trying an Android beginner's tute (http://mobile.tutsplus.com/tutorials/android/android-sdk-development/) the "R.id cannot be resolved" error had me stumped too. In my case it was an android:onClick in /res/layout/main.xml. It seems onClick is not supported in AVD platform 1.5 API level 3.
A change to a new AVD with platform 1.6 API, level 6 removed the error - also started the project from scratch with the new api and level settings. For absolute Eclipse newbies (like myself) create a new AVD with:
Window -> Android SDK and AVD Manager -> New. Select platform, level number from "Target" drop down list.
Also try deleting the ~.android\debug.keystore (Happened to me, thought it was due to R.id issue). Real problem was debug.keystore was older than a year!
I ran into this problem when I tried to follow Lars Vogel's Android development tutorial...it turns out my problem is simply because I didn't save the layout file. Once I save the file, it works fine.
make sure you do not have any xml files with capitals in the name.
I had the same problem.
all the file names in res (and all its sub folders including layout) must be lower case only. This includes image files, xml files, etc (even if they aren't referenced anywhere within the project.)
if you posted full your main.xml file, then it's not right. You must write a namespace of xml:
xmlns:android="http://schemas.android.com/apk/res/android"
for example:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/label"
android:layout_width="78dip"
android:layout_height="65dip"
android:paddingTop="4dip"
android:textSize="12dip"
android:singleLine="true"
android:ellipsize="end"
android:textColor="#color/bright_text_dark_focused"
android:gravity="center_horizontal|center_vertical" />
Yeah another fix
I started the emulator. By running a helloandroid program, that did compile.
And got out of eclispe and got back in don't know which one fixed the problem..
Cleaning the project etc didn't fix it - can i have 2 hrs of my life back!
import com.TestApp.R;
isn't accepted once R is lost.
My Eclipse now auto creates a new "res" folder everytime I "clean". Yes, I have two folders named "res" in parallel directly under my project folder. The auto created one is empty. String values are still found. No other errors than "R cannot be resolved" are reported by Eclipse.
Eureka! I've managed to make my first android project import to Eclipse!
Earlier I always got "Unable to find system library" under the project's Properties - Java build path - Libraries tab and it was impossible to correct it once it occured. The consequence was that no import statements could be resolved by anything imported.
In this case, I changed the JDK compliance level from 1.6 to 1.5 BEFORE I imported (afterwards its too late and cannot be mended). It must be done from Window - Preferences - Java - Compiler (earlier I thought this option was available only by right-clicking on already imported project). Then right-click on each project and set Properties - Android to a suitable Target (with the errors above, eclipse ignores any selection here). Then, I could even change back to JDK compliance level 1.6.
So, in general, changing the JDK compliance level before importing, might help.
And when deleting a project ALWAYS check the "Delete project content on disk (cannot be undone)" checkbox in the "Are you sure" dialog. Otherwise it is impossible to re-import the project, o if you've imported it with the wrong JDK compliance level the first time, it is impossible to correct the mistake, other than to try in another workspace.
These are the experiences of a very frustrated Eclipse user.
Make sure there is not a hidden error in one of your .xml files.
Sometimes you can delete a statement in the strings.xml file that is important.
For example, in the Vogella example, I got the error:
Error: No resource found that matches the given name (at 'title' with value '#string/menu_settings').
I had deleted the line:
<string name="menu_settings">Settings</string>
Putting this back in or deleting res/menu/main.xml would solve the error.
I had the same problem but got fixed
i dont know exactly how this problem gonna fix
Just try, It might be helpful
add this code at the top of ur code
import com.MyFirstApp.activities.R;
here com.MyFirstApp.activties is my component name replace it with your component name