I'm writing an android plugin for unity to be able to check if notifications are enabled for the game. I have one java class with a method for checking if notifications are enabled. When i build the plugin and then the .apk with unity everything works fine. But after installation, when calling the mehthod i get the following exception:
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/app/NotificationManagerCompat;
The Java class
package com.example.plugin;
import android.app.Activity;
import androidx.core.app.NotificationManagerCompat;
public class NotificationPlugin {
public static boolean areNotificationEnabled(Activity unityActivity) {
return NotificationManagerCompat.from(unityActivity).areNotificationsEnabled();
}
}
buld.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
gradle.properties
org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
android.enableJetifier=true
Haven't found a solution anywhere else yet. Thank in advance. It's probably a super simple fix that i miss.
Update
Custom gradle.properties in unity set with android.enableJetifier and android.useAndroidX set to true
Jetifier was enabled in unity
Androidx.Core libary was added to the dependencies of the gradle.build file of the plugin
None of the above solved the issue
Solution
As Hamid Yusifli suggested in his answer a custom gradle build template needs to be enabled (Project Settings>Player>Publishing Settings>Custom Main Gralde Template) and the dependencies for the libary need to be added (implementation 'androidx.core:core:1.5.0' in my case). This solved the issue.
So, seems like in your case unity ignores your library gradle dependencies,
there are many different reasons why this could happen. To force unity to include missing dependencies you must provide a custom Gradle build template and add your dependencies in that file.
Related
Views stopped showing on Design Mode in Android Studio out of the blue (including the "hello world" textView). I haven't updated anything or changed anything.
I tried the following solutions:
(changing the theme) This view is not constrained android studio. I can not see the button even if I use Infer Constraints
inferring constraints.
(can't find the link) but the answer marked as correct said my SDK is corrupt -> updating it didn't work.
I'm suspecting Gradle is the culprit somehow, so here's the app's build script (a brand new project):
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.cc.take6"
minSdkVersion 28
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
my android Studio is version: 3.6.3.
Any ideas? thank you in advance.
Make sure you are using the latest stable version of Android Studio and all related tools
Update your project to use latest version of Gradle and everything
File -> Invalidate Caches and Restart
Build -> Clean Project
Build -> Rebuild Project
Run
I fixed the problem by changing the version of contraintLayout implementation that I was using. I added to the file build.gradle(:app):
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
I am trying to develop an SFTP client using sshj on Android studio such that the App can connect securely to the server using SFTP over ssh. The code was running fine, but when I added the "sshj-0.10.0" module, it gives me this complicated error.
The "sshj-0.10.0" module is needed to run server code using net library as below:
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.sftp.SFTPClient;
I added the module the project and configured it in the dependencies in build.gradel of the app as shown below:
What I have tried so far (but not limited to):
1- Clean Project then Rebuild Project - failed
2- Invalidate Caches / Restart - failed
3- Delete .gradle and .idea from my root project- failed
4- Added
android {
defaultConfig {
multiDexEnabled true
}
}
and
dependencies {// Multidex
implementation 'com.android.support:multidex:1.0.3'
implementation project(path: ':sshj-0.10.0')
}
No solution was worked with me.
Here is my build.gradle(:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.mohsenali.autosen"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
android {
defaultConfig {
multiDexEnabled true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//TedPermission
implementation 'gun0912.ted:tedpermission:1.0.3'
implementation files('D:/SKKU_PhD/Android/workspace_2018_projects/AutoSen/app/libs/commons-net-3.7.1.jar')
// Multidex
implementation 'com.android.support:multidex:1.0.3'
implementation project(path: ':sshj-0.10.0')
}
I know that this kind of error is popular but I tried many possible solutions available on SO since two days ago but none of them has helped me. So please don't mark it duplicated, maybe someone could help. Thanks.
Finally, I solved this error bu creating "libs" folder in the root of "app" project, and added the .jar library to it. After that I updated the code in "build.gradle(:app)" by adding this line: "implementation files('path to/app/libs/jsch-0.1.55.jar')".
I have updated my android build.gradle to latest version now i am getting an error.
I have searched answers regarding this here(stackover flow),but none work for me .
my build.gradle code is:--->
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.parse.starter"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
when i click on "sync now" then the error appears as:--->
This project uses AndroidX Dependencies,but the 'android.useAndroidX' property is not enabled.
After searching some answers here(stackover flow) .i created a file 'gradle.property' from File>new>Files(named as gradle.property) and added codes on it as:--->
org.gradle.jvmargs=-Xmx2048m
android.useAndroidX=true
android.enableJetifier=true
After doing this when i click again on "sync now".then again the same error appears (This project uses AndroidX Dependencies,but the 'android.useAndroidX' property is not enabled.)
I dont know how to fix this issue.
please Help
thankyou.
Try this solution go to :
Refactor -> Refactor this -> Migrate to Androidx -> click migrate , then a pop up message will show up to ask you if you want to save a copy of the project by ticking that checkbox ( up to you ) --> then do refactor
You might have migrated to android x manually
Try using built in migrator
https://developer.android.com/jetpack/androidx/migrate
Just right click , then go to refractor> migrate to AndroidX
I've tried all the ways found on StackOverflow and still facing the issue.
I've created a demo Android project with native support, added a library to it and moved all native code into the library.
Now I'm unable to stop on breakpoints in native code, native debugger became active only after a SEGFAULT crash.
I've added defaultPublishConfig "debug" into mylibrary build.gradle and debuggable true to app build.fradle. There was enough for native debugging earlier. But it is not working since Android Studio upgrade.
Here are the full build.gradle files
app
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.raistlin.myapplication"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation project(path: ':mylibrary')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
mylibrary
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
defaultPublishConfig "debug"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments "-DANDROID_TOOLCHAIN=clang"
cppFlags "-fexceptions", "-std=c++11", "-DJSONCPP_NO_LOCALE_SUPPORT"
version "3.10.2"
}
}
}
buildTypes {
debug {
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
First, check debug variant is selected for library.
As your build.gradle has a setting, path "src/main/cpp/CMakeLists.txt", it won't build I think. So set targets, rebuild and check again.
If breakpoints doesn't work after build, old garbage may be left in the build cache and causes problems. Open project directory in explorer and delete build cache (.externalNativeBuild folder) manually and build the project again. I also delete build folder, as it contains .so files in intermediate directory, but it's optional.
Android Studio does not clean libraries in the test device. They are overwritten basically, but clear them manually depending on needs. Files are in /data/app/(package name)/lib/(cpu arch.)/.
NB: Synchronize menu of device file explorer does not synchronize properly under lib or (cpu arch.) directory. To synchronize, select /data or /data/app and choose Synchronize.
NB.1 If targets is omitted, Android Studio seems to build no targets. The built output is in (project)/app/build/intermediates/cmake/(flavor)/obj/(cpu architecture). If it seems to work without any targets, check files on device. They confuse test results.
NB.2 debuggable true is for release build to enable debugging. No need to set it for debug build, as debuggable flag is set as default.
NB.3 Seems version dependent but Gradle in Android Studio does not clean .externalNativeBuild tree properly even if clean or rebuild is called, and confuses native code build configs. It was around AS3.0, as I remember.
NB.4 My environment is
Android Stuidio 3.2.1
classpath 'com.android.tools.build:gradle:3.2.1'
gradle-4.7-all
CMake: default(3.6.4111459)
I know there are newer versions for Android Studio, Gradle and CMake but they are buggy, so I chose current environment. As far as I've experienced, Android Studio 3.3, gradle:3.3.0, gradle-4.10.1-all have severe bug in VCS(git). Wrong file contents are shown in editor and build fails, sometimes. Setting CMake version to 3.10.x (3.10.2 for me) also seems buggy.
Here's a copy from my project as a sample, partially modified from original one but may work.
I've checked breakpoints in a library work in Android Studio 3.2.1.
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "0.0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'proguard-rules.pro'
externalNativeBuild {
cmake {
cppFlags "-std=c++11"
arguments "-DANDROID_STL=c++_static"
targets "sample"
}
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Update
targets is mentioned here Guide - Link Gradle to your native library - Specify optional configurations.
I am trying to import 3 Gradle Projects I used in all my apps with utilities to a new project.
I create the new project and then File -> Project Structure -> + -> Import Gradle Project
Then I click Finish but those 3 projects do not appear in the modules list
No error has appeared yet. But when I click Ok there I do got 4 IDE fatal errors:
1/4
Element: class org.jetbrains.plugins.groovy.lang.psi.impl.GroovyFileImpl because: different providers: SingleRootFileViewProvider{myVirtualFile=file://F:/development/workspaces/Orchestram/settings.gradle, content=VirtualFileContent{size=16}}(2177d6ca); SingleRootFileViewProvider{myVirtualFile=file://F:/development/workspaces/Orchestram/settings.gradle, content=VirtualFileContent{size=16}}(16a77aa0)
2/4
Element: class com.intellij.psi.impl.compiled.ClsFileImpl because: file://F:/development/workspaces/Orchestram/app/callRemoteService/build/intermediates/classes/debug/com/qbitera/CallRemoteService/R.class is invalid
3/4
Element: class org.jetbrains.plugins.groovy.lang.psi.impl.GroovyFileImpl because: different providers: SingleRootFileViewProvider{myVirtualFile=file://F:/development/workspaces/Orchestram/settings.gradle, content=VirtualFileContent{size=16}}(344f03e4); SingleRootFileViewProvider{myVirtualFile=file://F:/development/workspaces/Orchestram/settings.gradle, content=VirtualFileContent{size=16}}(4940c49e)
4/4
Error while applying changes
This is my build.gradle before trying to import those modules (it does not change)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.qbitera.cerqana.orchestram"
minSdkVersion 14
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '27.0.3'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
And the settings.gradle
include ':app'
Of course if I try to just include the implementation project(':callRemoteService') line in the Gradle it fails. But if try to import againg the modules from the Project Structure, it says that it is already on the project
Add to settings.gradle at the root folder:
include ':app'
include ':your_module'
include ':your_second_module'
include ':you_got_the_point'