I implements a project in Intellij Idea with kotlin . this is working without Error . this is my Intellij project photo without Error
but when i implement this project in Android Studio , i got Error because the studio can not find this method in BigInteger class
longValueExact()
Android Studio project photo :
I have one JDK in my computer (v 1.8) . but in Itellij project this method worked and in android studio not worked.
i opened java.math.BigInteger class in android studio and saw longValueExact() method :
kotlin class :
open class AuthKey(val key: ByteArray) {
constructor(key: ByteBuffer) : this(key.array())
init {
if (key.size != 256)
throw RuntimeException("AuthKey must be 256 Bytes found ${key.size} bytes")
}
// see https://core.telegram.org/mtproto/description#key-identifier
// SHA1 generates 20 bytes long hash, authKeyId is the lower 8 bytes
val keyId = CryptoUtils.substring(CryptoUtils.SHA1(key), 12, 8)
fun getKeyIdAsLong() = BigInteger(keyId).longValueExact()
}
class TempAuthKey(key: ByteArray, val expiresAt: Int) : AuthKey(key)
it mean we have this class in java 1.8 and we added this in android studio . and android studio loading this class with all methods in external library . but we cant use these methods in project classes!
any one can help me ?
Android has its own implementation of java.whatever classes and can have different interfaces as well, especially when it comes to things added in recent Java versions. At https://developer.android.com/reference/java/math/BigInteger.html you can see even the latest Android API (25) doesn't have this method. So if you managed to compile the program, it would fail to actually run on the device.
The <1.8> external library is not used for Android projects, if you look in module dependencies you shouldn't see it.
UPDATE - This method and the other "value exact" methods were added to Android in API 31.
Related
I have a Xamarin.Android project (as a part of a Xamarin.Forms project) where I use network-security-config.xml to allow traffic to/from a test server using http.
I wonder if there is a way to exclude this from release build.
I found out two approaches, but none of them seem to apply to my situation:
If I was using Android Studio, I could have two different files, in different folders, one for debug and one for release. I think this is not supported in Visual Studio/Xamarin.
There is a directive in network_security_config.xml, "", but I think it only applies to CA certificates.
Any clue?
Thank you!
In your Android project you can create your own Application class and extend the Android.App.Application class. This way you can enable/disable debugging of the app also.
The build will now that this is your manifest's Application node when you apply an ApplicationAttribute to it like so:
#if DEBUG
[Application(Debuggable = true, NetworkSecurityConfig = "#xml/network_security_config")]
#else
[Application(Debuggable = false)]
#endif
public class MainApplication : Android.App.Application
{
}
Where network_security_config is your configuration file.
I've got a static library, which was used to generate the wrapping code by Sharpie. The library was Built after that (including, generated *.dll) successfully.
AppDefinition.cs contains the namespace and the mappings, like this:
namespace TheNamespace
{
// #interface TheParameters : NSObject
[BaseType(typeof(NSObject))]
interface TheParameters
{
The library itself built in Release mode with LinkTarget.ArmV7 | LinkTarget.ArmV7s | LinkTarget.Arm64.
However, when referencing this binding project from my iOS project, it works only in Debug mode.
When I change it to Release, the namespace (and all the related clasees) not available. Also, when exploring the binding library reference in Object Browser, it doesn't display any elements: it's totally empty.
Just to point that: it gets available when changing it in the dropdown to Debug and disappears on Release, what's interesting, undependently on what actually project is selected in Current Project dropdown!
What might be the issue? Thanks!
I think the problem should come from when building static library .When generating static library , there is a build type of release/debug to select.
Above screenshot shows static library types after building , there are three types (Two is Debug and One is Release ). You can see that tt distinguishes between release and debug .
After some Googling I found the solution.
The issue happens because of Visual Studio bug, I guess. And also referred here. (And it's weird it's not mentioned in Xamarin docs on Microsoft website.
To resolve the issue the Binding Project(s) must not reside in the same solution with the main project. Just remove them and attach the library as regular reference.
I am trying to write a Xamarin Android binding library for a library that is loaded in the app during runtime. When using this library in a normal Android project, you would use "compileOnly".
compileOnly 'de.robv.android.xposed:api:82'
compileOnly 'de.robv.android.xposed:api:82:sources'
From my understanding, "compileOnly" makes the code from the library available for compilation but does not add it to the resulting apk. Meaning it needs to be provided in runtime for the app to work.
When reading the Xamarin binding Build Action docs, "compileOnly" sounds very similar to "InputJar".
Does not embed the .jar into the resulting Bindings Library .DLL. Your Bindings Library .DLL will have a dependency on this .jar at runtime. Use this option when you do not want to include the .jar in your Bindings Library (for example, for licensing reasons). If you use this option, you must ensure that the input .jar is available on the device that runs your app.
However, when compiling my application while using methods provided by the runtime library, I get errors from the generated java code that the packages do not exist.
javac.exe error : error: package de.robv.android.xposed does not exist
javac.exe error : de.robv.android.xposed.IXposedHookLoadPackage
javac.exe error : error: package de.robv.android.xposed.callbacks.XC_LoadPackage does not exist
javac.exe error : public void handleLoadPackage (de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam p0)
error : error: package de.robv.android.xposed.callbacks.XC_LoadPackage does not exist
error : private native void n_handleLoadPackage (de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam p0);
Meaning that the code was not made available during compilation. How can I make sure the code is made available during compilation but not embedded into application?
See my answer at https://stackoverflow.com/a/64973909/4374462
Either using AndroidExternalJavaLibrary or [assembly: Java.Interop.DoNotPackage("ref.jar")].
Recently received a new Android SDK (aar) to bind in Xamarin. When initially starting the binding I receive the error
COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
This error is due to the SDK containing Java 8 (v1.8) byte code and it needs to be compatible with Java 7 (v1.7) to support lower API versions of Android.
In your Android project (not the binding project), add the following property.
<AndroidEnableDesugar>True</AndroidEnableDesugar>
or if you are in VS 2019+ you can turn on D8 which enables this by default.
<AndroidDexTool>d8</AndroidDexTool>
Desugaring is the process of allowing Java 8 byte code to be converted into Java 7 compatible byte code. This is a Google process that performs the conversion and is part of the Xamarin.Android build process.
Then if the SDK doesn't have any dependencies, it should all work. If you have EmbeddedReferenceJars, then things get more complicated.
In Visual Studio 2017 you will experience errors similar to
Error: java.lang.TypeNotPresentException : Type io.reactivex.functions.Consumer not present
It will be unable to find these types in reference jars, because the desugaring processing isn't working properly. From Github Issues you eventually find the reason:
The first fix here is to add the `--classpath_entry` flag for every
`--input`, for some reason `Desugar` is not treating `--input` jars as
classpath entries
The bug is already tracked and fixed in Visual Studio 2019 Preview 2.
Now you switch to Visual Studio 2019 Preview 2 and you will come across this error.
Java.Lang.NoClassDefFoundError: Failed resolution of: Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension;
The desugaring processing is failing again because it needs this class to help communicate to the desugared code.
The class ThrowableExtension is actually found: https://github.com/bazelbuild/bazel/blob/master/src/tools/android/java/com/google/devtools/build/android/desugar/runtime/ThrowableExtension.java
You then take that Java class and you can compile it into a jar. A quick way to do it is copy that java file into a folder. Then inside that folder create a folder called output.
Call this command
javac -d ./output ThrowableExtension.java
Then move into the output directory and call this command
jar cvf desugar.jar *
It will create desugar.jar. Add that as an EmbeddedReferenceJar in your Android binding project. Your binding with Java 8 byte code with desugaring should now work.
Hopefully this might be resolved in a future Visual Studio version, so all these steps aren't necessary, but until then, at least you know what is happening and how to fix it.
We are actually analyzing what we have to do if we migrate our application from VS2005 up to VS2010.
What i have done:
I opened all solutions in VS2010 and let convert vs the projects.
At the moment the production assemblies dont get an upgrade of the .NET Framework,
it has to target the framework 2.
The framework version of the unit test assemblies (MSTest) is switched to the version 4 by VS2010 automatically,
thats ok so far.
The Problem:
Some unit tests are failing cause they can't access a config file through the ConfigurationMananger.OpenExeConfiguration(ConfigurationUserLevel.None) call.
The following exception is thrown:
System.Configuration.ConfigurationErrorsException: An error occurred
loading a configuration file: Type is not resolved for member X ...
System.Runtime.Serialization.SerializationException: Type is not
resolved for member X
The member X is derived from GenericIdentity and is marked as [Serializable].
All needed files (configuration, assemblies) are up to date and are correctly deployed in the output folder.
I tried to switch the framework version of the production assemblies to version 4, but it didn't help.
I found this ressources, but they dont helped me.
post from stack
Anybody has an idea why i get the described behavior?
If i change my Identity from
public MyIdentity : GenericIdentity
{ }
to
public MyIdentity : MarshalByRefObject, IIdentity
{ }
all of my tests are gettin green.