Error in strings.xml: invalid symbol 'continue' - android

In my strings.xml file I have
<string name="continue">Continue</string>
I can't build my project because of the error: "Invalid symbol: 'continue'". Why I can't use such a name?

It's because continue is a reserved symbol in Java, so you cannot use it as a name for any object in your XML files or Java code.
The reason this is a problem is that the XML defined in your project is translated into Java code that the Dalvik VM can understand. So, your code above translates into the following in R.java:
public final class R {
public static final class string {
public static final int continue=0x7f040000;
}
}
The problem is more obvious when examining the (would-be) generated code.
See list of reserved Java symbols for others to avoid.

"continue" is a Java keyword and the R.java would not compile.
public static final int continue=0x7f040001;
the above code would cause an "Syntax error on token "continue", invalid VariableDeclaratorId" error.

Related

Android binding library: Type or namespace not found

I developed a Android Binding Library to bind a printer Android AAR file (The AAR has its build action set to LibraryProjectZip), and the project is compiled using Android 7.1, using class-parse android class parser, and AndroidCodeGen Target: XAJavaInterop1. I can provide the simple Project in order to have full access to the code and library.
But I have the following error: 'The type or namespace 'ILibrary' does not exist in the namespace 'Com.Sun.Jna' at Com.Sun.Jna.Native.cs. So I decided to check at the Android library using a decompiler and here is what I found:
The AAR file contains an interface 'Library' (not ILibrary), and the Native.class file contains a method whose signature is the following and is the source of the error and which requires a Library object as input
public static Library synchronizeLibrary(final Library library){...}
The C# generated code contains a Com.Sun.Jna.ILibrary.cs file which contains a public abstract class 'Library':
[Register ("com/sun/jna/Library", DoNotGenerateAcw=true)] public abstract class Library : Java.Lang.Object {...}
but the generated Native.cs file has the counterpart method SynchronizeLibrary :
// Metadata.xml XPath method reference: [Register ("synchronizedLibrary", "(Lcom/sun/jna/Library;)Lcom/sun/jna/Library;", "")] public static unsafe global::Com.Sun.Jna.ILibrary SynchronizedLibrary(global::Com.Sun.Jna.ILibrary library) {...}
I do not understand why the C# generated method SynchronizedLibrary demands an ILibrary and not the Library.
I tried to modify the Metadata.xml file to rename the class Library to ILibrary but with no success. Moreover I have a warning saying that:
class-parse: warning: could not load .jar entry 'libjnidispatch.jnilib': System.Argument.OutOfRangeException,
I tried to change the name of the interface from Library to ILibrary using <attr path="/api/package[#name='com.sun.jna']/class[#name='Library']" name="managedName">ILibrary</attr> but the definition of the interface does not change. It is strange that I have a reference path for the members of the interface but not the interface itself
[Register ("com/sun/jna/Library", DoNotGenerateAcw=true)]
public abstract class Library : Java.Lang.Object {
internal Library ()
{
}
// Metadata.xml XPath field reference: path="/api/package[#name='com.sun.jna']/interface[#name='Library']/field[#name='OPTION_ALLOW_OBJECTS']"
[Register ("OPTION_ALLOW_OBJECTS")]
public const string OptionAllowObjects = (string) "allow-objects";,
and I do not know if it is related to the prior problem.
Thank you for any suggestion
Finally, I found the way to correct the error by modifying the name of the interfaces by adding the following lines to the Metadata file:
<attr path="/api/package[#name='com.sun.jna']/interface[#name='Library']" name="name">ILibrary</attr>
But now I have errors telling me that JNIENv does not contain method like NewString. And I am wondering if it is related to the warning i have telling me that It cannot load .jar entry libjnidispatch.jnilib
Any ideas, thanks

Android JNI - how to import function from shared object

Please Excuse my absolute lack of Android JNI
I want to analize/call one function hidden in shared object: libEncodeAndDecodeUtils.so
orginal code uses it like this:
package com.midea.msmartsdk.common.utils;
public class EncodeAndDecodeUtils {
public native String esha(String str, String str2, String str3);
}
Ida decompiler shows:
Java_com_midea_msmartsdk_common_utils_EncodeAndDecodeUtils_esha
How can I call this function in my project?
My current attempt:
new AndroidStudio project with JNI support
adding folder \src\main\jniLibs\armeabi-v7a
copy libEncodeAndDecodeUtils.so to armeabi-v7a
buid.bradle android{ defaultConfig { ndk {abiFilters "armeabi-v7a"} }
and creating class
package com.midea.msmartsdk.common.utils.so_test4;
public class EncodeAndDecodeUtils {
static {
System.loadLibrary("EncodeAndDecodeUtils");
}
public native String esha(String str, String str2, String str3);
}
this lead me to error:
E/zygote: No implementation found for
java.lang.String com.midea.msmartsdk.common.utils.so_test4.EncodeAndDecodeUtils.esha
(java.lang.String,
java.lang.String,
java.lang.String)
(tried
Java_com_midea_msmartsdk_common_utils_so_1test4_EncodeAndDecodeUtils_esha
and Java_com_midea_msmartsdk_common_utils_so_1test4_EncodeAndDecodeUtils_esha__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2)
is this my problem?
Java_com_midea_msmartsdk_common_utils_EncodeAndDecodeUtils_esha
!=
Java_com_midea_msmartsdk_common_utils_so_1test4_EncodeAndDecodeUtils_esha
If you try to access esha from your own code, then you HAVE TO declare this method exactly the same as its original form, because JNI will try to find the implementation following some fixed convention. According to https://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/design.html
Resolving Native Method Names
Dynamic linkers resolve entries based on their names. A native method name is concatenated from the following components:
the prefix Java_
a mangled fully-qualified class name
an underscore (“_”) separator
a mangled method name for overloaded native methods,
two underscores (“__”) followed by the mangled argument signature
Simply speaking, it will be something like Java_packagename_ClassName_methodsignature.
For example, in your case, it is Java_com_midea_msmartsdk_common_utils_EncodeAndDecodeUtils_esha.
So, try to remove so_test4 from your package name.

CS0103 The name 'Resource' does not exist in the current context

While I create android app in Visual Studio with Xamarin I got strange error - CS0103 The name 'Resource' does not exist in the current context. When I do Clean and then Build, there are no any problems, build is success. But when I changes something in code, Error appears again.
I tried to make changes according this post but all file names in Resources folder are ok. Can anybody help me with this problem?
short:
make sure your Namespace is same across all these files that is mentioned below ;
Resource.Designer.cs
every Activity that procudes error:"cs103 resource doesnt exist .."
yourproject.csproj (edit vith notepad)(verify "RootNamespace" ,"AssemblyName" is same with your namespace )
after you make them all same Namespace clean+build should work
long:
if you have changed namespace in anywhere in the project,
you gotta Find And Replace oldNameSpace to NewNameSpace inside yourProjectName.csproj file
(open with text editor outside of vs2015 ide)
why ??
when you compile project namespace in the Resource.Designer.cs is overwritten with this values from csproj file
Any Activity:
namespace yourNew_NameSpace // <-- Attention here !!!!!!
{
[Activity(Label = "asdf", MainLauncher = true )]
public class act_main : Activity
{
TextView tv_camResolution;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.ly_main);
tv_camResolution = FindViewById<TextView>(Resource.Id.textView1);
}
......
.csproj file :
....
<RootNamespace>OldNameSpace</RootNamespace>
<AssemblyName>OldNameSpace</AssemblyName>
....
Resource.Designer.cs:
//▼▼▼below see oldnamespace
[assembly:global::Android.Runtime.ResourceDesignerAttribute("OldNameSpace.Resource", IsApplication=true)]
namespace OldNameSpace // <--- and here see oldnamespace
{
....
I have the same error, but my code compile. so its maybe related to the wrong import or ambiguous Resources object. Note that there is Resources and Resource i believe Resources is coming from android sdk.

Android databinding build error: constant expression required

I am writing Android application using DataBinding by referencing https://developer.android.com/topic/libraries/data-binding/index.html.
But while building my project, It is showing an error in generated class as
> '/databinding/DataBinderMapper.java:10: error: constant expression
> required.'
This error is happening in switch statement inside generated class DataBinderMapper.java (This file is an auto generated file for databinding)
Any one knows the reason for this java switch case error happening in Auto generated buld file?
Edits:
I found the reason for this issue is, layout reference created in R.java file is not final for this case.
For example, in my case layout reference in R.java is
public static int activity_main=0x7f04001c;
Actually it should be
public static final int activity_main=0x7f04001b;
But I don't know the reason for this happened and how to change it to final.
Probably your model that you are binding against has final modifiers in its variables.
This error happens when your project has dependency with library or external plugin apart from application.
The reason for this issue is, the ids generated might clash when you have dependency with multiple library/ plugins.

Android studio keeps adding illegal line to R.java

I'm coding an Android app and so I put a 0.gif image to all the drawable-XXXX folders. When trying to build, android studio threw an error:
/Users/ziga/Desktop/GimVic-suplence-android/app/build/generated/source/r/debug/com/zigapk/gimvic/suplence/R.java
Error:(28, 32) error: expected
Error:(28, 34) error: illegal start of type
Error:(28, 35) error: expected
After googling, I realized that this is caused, by this code in R.java:
public static final class drawable {
public static final int 0=0x7f020000; //here is an illegal statement
public static final int bg_card=0x7f020001;
public static final int bg_card_green=0x7f020002;
public static final int ic_launcher=0x7f020003;
public static final int ic_launcher_web=0x7f020004;
public static final int santa0=0x7f020005;
public static final int smile=0x7f020006;
}
I renamed my image to santa0.gif and tried to build again: same error was thrown :/
Thew I tried to erase this line and build again: same problem occurred.
What to do??
Thanks in advance :)
I put a 0.gif image to all the drawable-XXXX folders
Resource names need to be valid Java data member names. Java data member names cannot start with a number.
I renamed my image to santa0.gif and tried to build again: same error was thrown
If I had to guess, you did not rename all copies of 0.gif, but only one.
Usually when such weird problems occur, cleaning the project helps. That can be done with the following menu options in Android Studio.
Build -> Rebuild Project
Build -> Clean Project
Ctrl + Shift + F (Windows) search for "0."
Cmd + Shift + F (Mac)
You will find it if it exists.

Categories

Resources