How to check Android 12 API level? - android-studio

I am trying to check the android 12 API level using the below code.
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
{
// Do something for Android 12 and above versions
}
else
{
// Do something for phones running an SDK before Android 12
}
but always execute else part when the run application in the android 12 beta device.
is it another way to check the android 12 beta version?

To also detect Android 12 Beta versions you can use Build.VERSION.CODENAME like this:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S || "S".equals(Build.VERSION.CODENAME)) {
// Android 12 or Android 12 Beta
}

BuildCompat.isAtLeastXX(), XX is your target version.
if (BuildCompat.isAtLeastS()) {
//Checks if the device is running on a pre-release version of Android S or a release version of Android S or newer.
}
https://developer.android.com/reference/androidx/core/os/BuildCompat#isAtLeastS()

Related

creating Android Studio plugin using IntelliJ `runIde` can not be invoked

Working on creating an android studio plugin using IntelliJ .
Following the guide https://plugins.jetbrains.com/docs/intellij/gradle-build-system.html using the Gradle
and the android studio plugin guide https://plugins.jetbrains.com/docs/intellij/android-studio.html#configuring-the-plugin-pluginxml-file
After created the project using the wizard and added the section runIde.
I am getting an error.
Expression 'runIde' cannot be invoked as a function. The function 'invoke()' is not found.
here is the build.gradel.kts.
plugins {
id("java")
id("org.jetbrains.kotlin.jvm") version "1.6.20"
id("org.jetbrains.intellij") version "1.5.2"
}
group = "com.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
// Configure Gradle IntelliJ Plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
intellij {
version.set("212.5712.43")
type.set("IC") // Target IDE Platform
plugins.set(listOf("android"))
}
runIde {
// Absolute path to installed target 3.5 Android Studio to use as
// IDE Development Instance (the "Contents" directory is macOS specific):
ideDir.set(file("/Applications/Android Studio.app/Contents"))
}
tasks {
// Set the JVM compatibility versions
withType<JavaCompile> {
sourceCompatibility = "11"
targetCompatibility = "11"
}
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
patchPluginXml {
sinceBuild.set("212")
untilBuild.set("222.*")
}
signPlugin {
certificateChain.set(System.getenv("CERTIFICATE_CHAIN"))
privateKey.set(System.getenv("PRIVATE_KEY"))
password.set(System.getenv("PRIVATE_KEY_PASSWORD"))
}
publishPlugin {
token.set(System.getenv("PUBLISH_TOKEN"))
}
}
OS.
macOS Monterey version 12.4.
The IntelliJ info.
IntelliJ IDEA 2022.1.1 (Community Edition).
Build #IC-221.5591.52, built on May 11, 2022.
Android Studio info.
Android Studio Chipmunk|2021.2.1.
Build#AI-212.5712.43.2112.8512546, Build on April 29, 2022.
Your runIde needs to be in the tasks block:
tasks {
runIde {
// Absolute path to installed target 3.5 Android Studio to use as
// IDE Development Instance (the "Contents" directory is macOS specific):
ideDir.set(file("/Applications/Android Studio.app/Contents"))
}
}

Android Studio stuck installing application to Device after add jar library

I'm setting up a SignalR client with Android. I'm using Android Studio 3.3 with Gradle v3.0.1.
I'm using two SignalR deprecated jar library in project.
- signalr-client-sdk.jar
- signalr-client-sdk-android.jar
The problem starts after adding these two jar dependencies to project.
After adding jar libs, Android Studio suck in installing application on device.
I did same thing in other project on my friend's PC and it works. I don't know whats wrong with this?
=====
UPDATE
I tried with an other device... I installed GenyMotion Emulator and Created several kind of Virtual Machines.
Android Studio is going to install the application on vm with api level 16 but when trying to install on vm with api level 27(8.1) it stuck again.
Screenshot :
I could generate signed apk and install on phone. but can't install directly from Android studio.
UPDATE
Add these lines to your build.gradle of app module, within the android { }:
android {
splits {
abi {
enable true
reset()
include 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a'
universalApk true
}
}
packagingOptions {
exclude 'lib/getLibs.ps1'
exclude 'lib/getLibs.sh'
exclude 'lib/gson-2.2.2.jar'
}
}
Old Answer
Try these steps:
Step One: Add this dependency to your build.gradle:
implementation 'com.microsoft.signalr:signalr:1.0.0'
Step Two: Add these lines to your activity:
private final String serverUrl = "put your server url";
private HubConnection hubConnection;
hubConnection = HubConnectionBuilder.create(serverUrl).build();
if (hubConnection.getConnectionState() == HubConnectionState.DISCONNECTED)
hubConnection.start();
if (hubConnection.getConnectionState() == HubConnectionState.CONNECTED)
hubConnection.send("your method name at server", your arguments);
else if (hubConnection.getConnectionState() == HubConnectionState.DISCONNECTED)
hubConnection.start();
As you see at above, you don't need to add two signalR deprecated jar library in project.

Gradle error when using the android studio preview build for java 8

I downloaded the android studio 2.4 preview 6. It has support for java 8 without using jack. This is my application gradle filebuildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.4.0-alpha6'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task wrapper(type: Wrapper) {
description 'Creates the gradle wrapper.'
gradleVersion '2.8'
}
And this is my gradle-wrapper.properties file
#Thu Apr 13 15:20:48 IST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-all.zip
But I keep getting the error :
Error:Unable to find method 'org.gradle.tooling.model.gradle.GradleBuild.getIncludedBuilds()Lorg/gradle/tooling/model/DomainObjectSet;'
What could be leading to the error and how can I solve it? I have tried invalidate cache/restart.
Everything looks fine to me. If you're going to use a beta build you shouldn't rely much on it for reasons like this; it's too buggy. Downgrade to the older version if you're going to push something to production or sell it, and if you're just looking at the new features, change to an older/newer preview. Android studio isn't known for being built that well.
Agree with Alex, I had mostly all the same versions as you:
Dependencies: Grade 2.4.0-alpha6
Gradle Wrapper: gradle-3.4.1-all.zip
Android Studio 2.4 preview 7
Had exactly the same error after updating from Android Studio 2.4 preview 1.
I got off the Canary channel and downloaded stable version 2.3.1 - Problem solved.
I might try a preview again in a couple months but I've found the last couple to be super buggy.

UnsatisfiedLinkError, Cocos2D-x app crash on startup

My Cocos2D-x app is working only on android 22+ and crash in lower platforms throwing an exception java.lang.UnsatisfiedLinkError
App config:
Target SDK version 22 (Android Lollipop).
Min SDK is 14.
NDK r10c with eclipse.
Update:
Very useful answer https://stackoverflow.com/a/27093163/3547788
Old solution:
Possible fix by changing the ndkr10 to ndkr9 then the app will work for all android versions, For NDK10:
changing the target & min sdk at the manifest to 14
add APP_PLATFORM := android-14 to application.mk
clean and build.
Well you decide on the minimum version of Android to support and your game is then expected to run on all versions from that version to the latest version.
You cannot, for example, decide to support 2.3, 4.0.4 and 5.0.1, but not 4.4.2 and 5.0.
See <uses-sdk> reference.

Strange error about type defined multiple times with PCL

I have Xamarin.Android, Xamarin.iOS and Windows Phone 8 applications, both referencing common PCL library. Inside this library I am using HttpClient, and because WP8, I need nuget package Microsoft.Net.Http.2.2.22
Without enabling compression on HttpClient everything works fine on all 3 platforms. However, after changing code to
var handler = new HttpClientHandler();
if (handler.SupportsAutomaticDecompression)
{
handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
}
httpClient = new HttpClient(handler);
there is build error with the library on iOS (both Android and WP works fine with this) telling me about multiple definition of DecompressionMethods. What is strange - the second assembly mentioned in error is System.Net.Primitives.dll - which DOES NOT contain definition of DecompressionMethods (i even checked in ILSpy).
Of course, I tried clean solution, rebuild, close/open Xamarin Studio etc...
Error :
MyApiHttpClient.cs(30,50): error CS0433: The imported type `System.Net.DecompressionMethods' is defined multiple times
/Users/vtoth/myprototype/Services/CommonServices/../../packages/Microsoft.Net.Http.2.2.22/lib/portable-net40+sl4+win8+wp71+wpa81/System.Net.Http.Primitives.dll (Location of the symbol related to previous error)
/Library/Frameworks/Mono.framework/Versions/3.2.6/lib/mono/xbuild-frameworks/.NETPortable/v4.5/Profile/Profile49/System.Net.Primitives.dll (Location of the symbol related to previous error)
Task "Csc" execution -- FAILED
Done building target "CoreCompile" in project "/Users/vtoth/myprototype/Services/CommonServices/CommonServices.csproj".-- FAILED
EDIT:
Version info about dev environment:
=== Xamarin Studio ===
Version 4.2.4 (build 35) Installation UUID:
(...) Runtime: Mono 3.2.6
((no/9b58377) GTK+ 2.24.23 (Raleigh theme)
Package version: 302060000
=== Apple Developer Tools ===
Xcode 5.1.1 (5085) Build 5B1008
=== Xamarin.iOS ===
Version: 7.2.1.42 (Business Edition) Hash: 773c77c Branch: Build
date: 2014-04-18 15:39:16-0400
=== Xamarin.Mac ===
Xamarin.Mac: Not Installed
=== Xamarin.Android ===
Version: 4.12.3 (Business Edition) Android SDK:
/Users/vtoth/Library/Developer/Xamarin/android-sdk-mac_x86 Supported
Android versions:
2.1 (API level 7)
2.2 (API level 8)
2.3 (API level 10)
3.1 (API level 12)
4.0 (API level 14)
4.0.3 (API level 15)
4.3 (API level 18)
4.4 (API level 19) Java SDK: /usr java version "1.6.0_65" Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609) Java
HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
=== Build Information ===
Release ID: 402040035 Git revision:
1173cb1c45bc56cb702e82cd21a7c9d0cea4acbf Build date: 2014-04-17
13:45:52-04 Xamarin addins: 53bde0041263928e8bd64686f5ca5a8e4338dd76
=== Operating System ===
Mac OS X 10.9.2
After discussing in the comments, it seems to me that you are running an old version of Xamarin Studio, Xamarin.iOS, and Xamarin.Android.
Please make sure you have at least the following stable versions or newer (which are available on the stable channel currently:
Xamarin Studio: 5.0
Mono: 3.4.0
GTK#: 2.24.23
Xamarin.iOS: 7.2.3.39
Xamarin.Android: 4.12.4
XCode: 5.1.1
Please try updating and your problems should go away, plus you'll get a much nicer version of Xamarin Studio to work with!

Resources