I want to have androidTest resources specific to each app flavor. I found an answer on this site that indicated you can just make a resource directory androidTestFlavorName and it will be managed like all the other resources. So I have a directory app/src/androidTestFlavorName/res/values and a file strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="test_sec_code">aStringValue</string>
</resources>
I have a test class app/src/androidTest/java/com/company/package/StartupTest.kt. In that class:
val code = context.getString(R.string.test_sec_code)
test_sec_code is red, so the IDE doesn't like it, and the compiler reports: Unresolved reference: test_sec_code
My selected build variant is flavorNameDebug. So am I setting up these resources wrong, or is my goal not possible?
Edit:
I tried putting the resource in app/src/androidTest/res/values/strings.xml and it can't be found there either. Surely there must be a way to define test resources right? Hello, is this thing on?
I was using android studio version 3.0. Suddenly after opening my android studio some of class loaded like this. But the whole project runs well. Any solution will be appreciated.
try this,
copy the code to any text editor
delete DashboardActivity.java class
create new DashboardActivity.java class under Activity
replace the code of DashboardActivity and save
i found the solution,somehow the file got corrupted,i copy the file in a text file,create the class & reload the IDE.
http://developer.android.com/training/basics/firstapp/building-ui.html
I have been following this tutorial, but I have two errors, both "R cannot be resolved to a variable". I have made android apps (easy ones) in the past, and I remember this problem being fixed by checking whether or not I have an import R statement (which I don't) and whether or not the project has been cleaned before being built again (I cleaned it and I still get the error). I am at a loss as to what to do. Thanks!
*I also want to mention I did see the thread of the same title with 170 hits, and the solution of "delete the import R statement" does not apply to my problem (I don't think)
Thanks again
All code is straight from the link above, but here it is for convenience
activity_my_first.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<EditText android:id="#+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
MyFirstActivity.java
package com.example.myfirstapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
public class MyFirstActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_first);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_my_first, menu);
return true;
}
}
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">My First App</string>
<string name="edit_message">Enter a message</string>
<string name="button_send">Send</string>
<string name="menu_settings">Menu Settings</string>
</resources>
edit: When I clean the project, I get this message in the Console:
[2012-06-29 11:12:38 - MyFirstApp] W/ResourceType( 6140): Bad XML
block: header size 91 or total size 0 is larger than data size 0
[2012-06-29 11:12:38 - MyFirstApp]
C:\Users\zhong\workspace\eclipse\MyFirstApp\res\menu\activity_my_first.xml:2:
error: Error: No resource found that matches the given name (at
'title' with value '#string/menu_settings').
edit: added a line to layout xml file <string name="menu_settings">Menu Settings</string>
Fixed cleaning project errors, but I still can't run the project from the two R errors.
I'm working my way through the same example, and had the same (or very similar) problem.
Finally I noticed that there was a tiny little red x on the manifest.xml.
Sure enough, it was complaining about this:
android:label="#string/title_activity_hello_world" >
So I added:
<string name="title_activity_hello_world">Hello World</string>
to strings.xml and now it works.
I had the same issue while following the tutorial.
Cleaning the project or cleaning the imports did not solve the problem.
How the problem was (simply) solved : I quit Eclipse and relaunched it.
2 possible things
The package name specified in the Android Manifest isn't the same as the in the Java files.
Or, your IDE hasn't generated the R.java file in the gen/ folder. Try building again (despite the error) and it will usually clear it up.
Basically the R.java file is generated for you and in the same package so you can refer to it as simply R.
I had android:text="#string/button_send"
Which gave the error: No resource found that matches the given name (at 'text' with value '#string/button_send').
I tried to solve the error using the tuturial. But the tutorial fails to tell me to write all the lines required one by one. So I miss to write "<string name="button_send">Send</string>" in the strings.xml.
After adding the previous line the error disappear! Which I believe is something similar to the original problem in this thread.
So if I had copied the whole lines from the given tutorial it may had not happened, but by typing our-self is how I think is the best way of learning.
I found the solution:
go to your project->res->menu than open the XML file there and delete this line:
android:title="#string/menu_settings"
I deleted it and it start to work,after 3 hours of the same warning in the problem section.
It even make sense when you read it, "at title with value #string/menu_settings"
Pleas confirm there is no error in
1- Project folder
2- Problem View of eclipse
3- Console
4- error log as in image
You have to make sure to
Clean your project Project-->Clean
The /res directory doesn't contain errors (some files will show up
with a red icon on the file explorer)
Your imports doesn't contain this line import android.R;
Check that in AndroidManifest.xml, the attribute package has the
correct value. <manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="your.correct.package.name"
This fixed it for me:
https://stackoverflow.com/a/3259974/1538785
Seems like eclipse likes to add an import line to java files for no reason. Go onto your java file, hit ctrl+shift+o and all the import statements will appear. Delete the line that says import andriod.R
Right click on the Project, select "Android Tools" > "Add Support Library" > "Android Support Library, revision 11" > "Install"
In my case, the problem was that I was on 64-bit Linux, and the required 32-bit libraries were not installed, meaning that the build tools could not generate R.java.
Running this command, then cleaning the project, fixed the problem:
sudo apt-get install ia32-libs
Make sure the executables (aapt etc.) in sdk/build-tools/android-xyz/* are executable if you are running the default download on your Linux box...
I had the same error trying to do the first tutorial. To get the app to run I edited MainActivity.java so it looked like this
package com.example.myfirstapp;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
i have this line
public static final int text_view222=0x7f060077;
in my R.java file duplicate and cause error in my android application , any body know how to fix this.
UPDATE :
i have aslo other R file from another projects that came when i add them as a library project ..
i face this problem before and after spending 1 hour i found that i have a TextView which it id have a space character before the id name and another TextView without the space . so in you case you have this some where in your layout files.
look at the space before the id name.
<TextView android:id="#+id/ text_view222"
...
...
..
/>
and another one without space
<TextView android:id="#+id/text_view222"
...
...
..
/>
I had the same problem. My mistake was in two xml. file i have puted the following
android:id="#+id/ETclienteNuevoDireccion"
and another:
android:id="#+id/ETclienteNuevoDireccion "
I only had a space more to the end of the line.
Try to delete the file and then clean the project. Project > Clean...
Delete your R.java file.
Do a Project --> Clean
Restart eclipse.
R.java should automatically re-build (assuming there are no errors in your project).
I can't get the childbrowser to work on Android.
I have followed the instructions on: https://github.com/brycecurtis/phonegap-plugins/tree/master/Android/ChildBrowser/
I have installed Eclipse and all the other stuff needed to compile an
app and all works as it should.
It is running in the emulator and I can also create an apk file.
So now I'm trying to get the childbrowser to work, like below.
I added the childbrowser.java file in my workspace/appname/
src/com/phonegap/plugins/childBrowser/ folder.
And the childbrowser.js file in my workspace/appname/assets/www/
folder.
I have linked to the phonegap.0.9.4.js and the childBrowser.js
files in my index file.
I added this in the manifest file
> <activity android:name="com.phonegap.DroidGap"
> android:label="#string/app_name">
> <intent-filter>
> </intent-filter>
> </activity>
The link that should open the childbrowser looks like this:
Open
And it still isn't working? I'm just testing in the emulator as I don't have a android phone here right now, isn't the childbrowser working in the emulator?
Or have I missed something else?
Thanks.
I use phonegap.0.9.4.js as well and it is working for me. The childBrowser should work after PhoneGap JS throws event 'deviceready'. So I added the following code.
var url="http://www.google.com";
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.plugins.childBrowser.showWebPage(url);
}
Some tips, as I encountered some issues as well:
The javascript file I downloaded is childbrowser.js, all lowercase, not childBrowser.js
Make sure that ChildBrowser.java is compiled in the correct folder. Check eclipse bin folder
For an external web page use http:// in front.
The Javascript is a different for Android and iPhone. For example on Android you do not call ChildBrowser.install(); So example code is also different for iPhone/Android/BlackBerry
Try using phonegap.0.9.5.js and let knw if you have any problem.I followed the same link its working fine.
Check Eclipse's BuildPath.
Some Eclipse versions have a Build Path entry in the context-sensitive right-click on a file/folder, some you have to go to the root folder, right-click and select 'Properties', select 'Java Build Path', then select the 'Source' tab.
Verify your src folder includes 'All', and it and it's subfolders and the ClassBrowser.java file are not Excluded.
Also, create or open the res/xml/plugins.xml file and add this line in source mode:
<plugin name="ChildBrowser" value="com.phonegap.plugins.childBrowser.ChildBrowser" />
Also note Aschwin's tips.
Change:
a href="#" onClick="window.plugins.childBrowser.showWebPage("thewebpage.html");"
To:
a href="#" onClick="window.plugins.childBrowser.showWebPage('thewebpage.html');"
The double quotes are likely what is keeping it from working. I see this is an old post, but maybe this will help someone else.