I am always getting java.lang.ClassNotFoundException: ru.ooolpi.lpiapp.ui.activity.MainActivity. But I have such class. Later I discovered that my project files are missing from apk.
My build script:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
// classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.10.1'
//classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.0'
}
}
//apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
repositories {
maven { url 'https://github.com/donnfelker/mvn-repo/raw/master/' }
maven { url 'https://repo.commonsware.com.s3.amazonaws.com' }
jcenter()
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
compile 'com.squareup.dagger:dagger:1.2.2'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.squareup:otto:1.3.8'
apt 'com.squareup.dagger:dagger-compiler:1.0.1'
}
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
//applicationId "ru.ooolpi.lpiapp"
minSdkVersion 10
targetSdkVersion 22
versionCode 2
versionName "1.0.1"
multiDexEnabled true
}
packagingOptions {
// Exclude file to avoid
// Error: Duplicate files during packaging of APK
exclude 'META-INF/services/javax.annotation.processing.Processor'
exclude 'META-INF/notice.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE.txt'
exclude '.readme'
}
dexOptions {
jumboMode = true
javaMaxHeapSize "4g"
}
signingConfigs {
release {
storeFile file('../devcert.jks')
storePassword '123456'
keyAlias 'dev'
keyPassword '123456'
}
}
lintOptions {
//disable 'InvalidPackage'
abortOnError false
}
compileOptions{
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
zipAlignEnabled true // this is default for release
}
debug {
applicationIdSuffix '.debug'
minifyEnabled false
}
}
}
I tried to build with Android Studio and just with gradlew. Result is the same - my files are not included into apk.
Update:
My project structure
Have a look at your proguard config file.
Make sure you don't strip off any class that you use in your apk. To manually keep the classes, add these lines:
-keep class ru.ooolpi.lpiapp.** { *; }
-dontwarn ru.ooolpi.lpiapp.**
The issue was that I used different versions for dagger and it's compiler.
How it was:
compile 'com.squareup.dagger:dagger:1.2.2'
apt 'com.squareup.dagger:dagger-compiler:1.0.1'
It should look like:
compile 'com.squareup.dagger:dagger:1.2.2'
apt 'com.squareup.dagger:dagger-compiler:1.2.2'
So, Android Studio refused to highlight issues in my code (I don't know why these things are related).
Related
I have an Android project which has to include a Unity project as well. Without importing the Unity project, I can successfully generated the release build APK (signed APK). But after including Unity project, I am facing this issue:
4 subsequent errors are:
Program type already present: androidx.arch.core.internal.SafeIterableMap$Entry
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
Caused by: com.android.tools.r8.utils.AbortException: Error: Program type already present: androidx.arch.core.internal.SafeIterableMap$Entry
Error: Program type already present: androidx.arch.core.internal.SafeIterableMap$Entry
Steps I've taken to include the unity project into Android project:
Export the Unity project
Build the exported project as a library
Include the .aar file in the native android project
By native android app level gradle is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "application.package.name"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
externalNativeBuild {
cmake {
// arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_static'
cppFlags "-std=c++11", "-frtti", "-fexceptions"
}
}
ndk {
abiFilters 'armeabi-v7a'/*, 'arm64-v8a'*/
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
// ndkBuild {
// path 'src/main/jni/Android.mk'
// }
}
lintOptions {
abortOnError false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
aaptOptions {
noCompress "tflite"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}
configurations {
compile.exclude group: 'androidx.annotation', module: 'annotation'
// added after getting com.android.tools.r8.errors.CompilationError: Program type already present: androidx.annotation.AnimRes
}
repositories {
maven {
url 'https://google.bintray.com/tensorflow'
}
flatDir {
dirs 'libs'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation(name: 'tensorflow-lite', ext: 'aar')
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation "android.arch.core:runtime:1.1.1"
implementation "android.arch.core:common:1.1.1"
implementation project(':openCVLibrary341')
// compile 'org.tensorflow:tensorflow-lite:+'
implementation project(':macelibrary')
testImplementation 'junit:junit:4.12'
implementation(project(':unity')){
exclude group: 'androidx.arch.core' // added after reading the below linked question
}
}
Unity Project gradle file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
}
}
allprojects {
repositories {
google()
jcenter()
flatDir {
dirs 'libs'
}
}
}
apply plugin: 'com.android.library'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
android {
compileSdkVersion 29
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
ndk {
abiFilters 'armeabi-v7a'
}
versionCode 1
versionName '0.1'
}
lintOptions {
abortOnError false
}
aaptOptions {
noCompress = ['.unity3d', '.ress', '.resource', '.obb']
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
}
/*buildTypes {
debug {
minifyEnabled false
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
signingConfig signingConfigs.debug
jniDebuggable true
}
release {
minifyEnabled false
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
signingConfig signingConfigs.debug
}
}*/
packagingOptions {
doNotStrip '*/armeabi-v7a/*.so'
}
buildTypes {
release {
multiDexEnabled = true
}
}
}
This question is a duplicate of this question, but there is no answer to the original question and I don't have enough reputation to comment and ask about the issue. The only difference is, after reading this question, I removed Firebase from Unity project and tried to generate signed APK, that didn't help either, same error.
Please help me with this issue. Thanks in advance!
Solution:
I managed to solve this issue by removing the androidx.* libraries from the libs directory of the exported unity project.
Reason:
androidx.* libraries were already being included in the native android project. While including the Unity project as library, the library also had all these androidx.* libraries and these were causing this issue.
As it turned out, while exporting a Unity project as native Android project, Unity by default includes these androidx.* libraries. They are only needed if we want to build an APK out of that project. But for building a library out of it, these androidx.* libraries are not required.
I'm working on an Android library that allows communication with a Bluetooth device. The library itself has two important dependencies.
The goal is to make an .aar available of the library for others to include in their apps, with a sample app being available for reference.
I'm currently working on the sample app, and I've successfully imported the library into the app, but the library's dependencies are not being included so I'm receiving errors such as java.lang.NoClassDefFoundError: Failed resolution of: ...
It was my understanding that the library's gradle file would be used when compiling the library, but this does not seem to be the case?
My library's gradle file is as follows:
apply plugin: 'com.android.library'
apply plugin: 'me.tatarka.retrolambda'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.6.0'
}
}
repositories {
mavenLocal()
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
defaultConfig {
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
publishNonDefault true
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:support-annotations:25.3.1'
compile 'com.polidea.rxandroidble:rxandroidble:1.3.2'
compile 'com.github.zafarkhaja:java-semver:0.9.0'
testCompile 'junit:junit:4.12'
}
Any ideas?
I'm trying to import a Jgrapht library in my app, but every time i try to build APK, android studio shows me:
Error:Execution failed for task ':app:transformClassesWithPreJackPackagedLibrariesForDebug'.
com.android.sched.scheduler.RunnerProcessException: Error during 'TypeLegalizer' runner on 'private final synthetic int org.jgrapht.alg.vertexcover.-$Lambda$25.$m$0(java.lang.Object arg0)': Unexpected error during visit: com.android.jack.ir.ast.JReturnStatement at "Unknown source info"
What is the problem and how i can fix it? Please help me!
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
defaultConfig {
applicationId "it.univpm.gruppoids.iotforemergencyandnavigation"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
jackOptions {
enabled true
}
}
compileOptions {
incremental true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
repositories {
maven {
url "https://mint.splunk.com/gradle/"
}
}
packagingOptions {
exclude 'META-INF/services/org.apache.sis.storage.DataStoreProvider'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/MANIFEST.MF'
}
/*buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}*/
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.0.0'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:percent:25.0.0'
compile 'com.android.support:support-v4:25.0.0'
compile 'com.journeyapps:zxing-android-embedded:3.2.0#aar'
compile 'com.google.zxing:core:3.2.1'
compile files('lib/jgrapht-ext-1.0.0-uber.jar')
compile files('lib/jgrapht-ext-1.0.0.jar')
compile files('lib/jgrapht-demo-1.0.0.jar')
compile files('lib/jgraph-5.13.0.0.jar')
compile files('lib/antlr4-runtime-4.5.3.jar')
compile files('lib/jgrapht-core-1.0.0.jar')
}
And the other gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
/*maven {
url "https://plugins.gradle.org/m2/"
}*/
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'me.tatarka:gradle-retrolambda:3.3.0'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
apply plugin: 'me.tatarka.retrolambda'
task clean(type: Delete) {
delete rootProject.buildDir
}
The easiest way I can think of is to use maven, then simply add the dependencies to your project. That'll save you a lot of hassel in setting up JGraphT by yourself.
you can find how to use maven with android studio here: How to import Maven dependency in Android Studio/IntelliJ?
While JGraphT's dependencies are here under the "Maven Releases" section:
http://jgrapht.org/
I don't understand why this is happening.
Gradle sync failed: Timeout waiting to lock buildscript class cache for build file '/Users/user/Documents/android-studio-pubble/App/build.gradle' (/Users/user/.gradle/caches/2.2.1/scripts/build_bqh4uod6cat7u5cm5qkoye2ky/ProjectScript/buildscript). It is currently in use by another Gradle instance.
Owner PID: unknown
Our PID: 909
Owner Operation: unknown
Our operation: Initialize cache
Lock file: /Users/user/.gradle/caches/2.2.1/scripts/build_bqh4uod6cat7u5cm5qkoye2ky/ProjectScript/buildscript/cache.properties.lock
Consult IDE log for more details (Help | Show Log)
general gladle is:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven { url '/Users/user/Documents/sdk/extras/android/m2repository' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
}
}
App gradle file is:
apply plugin: 'com.android.application'
android {
signingConfigs {
pubblemod {
keyAlias 'testapp'
keyPassword 'testapp'
storeFile file('/Users/user/Documents/sdk/testapp.keystore')
storePassword 'testapp'
}
}
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.test.app"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.intellij:annotations:+#jar'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:support-v13:22.0.+'
compile 'org.apache.commons:commons-lang3:3.2.+'
compile 'com.jakewharton:butterknife:6.0.0'
compile 'com.afollestad:material-dialogs:0.7.7.0'
compile 'it.neokree:MaterialTabs:0.11'
compile 'com.github.johnkil.android-appmsg:appmsg:1.2.0'
compile 'com.cocosw:bottomsheet:1.+#aar'
compile 'de.psdev.licensesdialog:licensesdialog:1.7.0'
compile 'com.afollestad:material-dialogs:0.7.7.0'
compile 'joda-time:joda-time:2.7'
compile 'com.google.android.gms:play-services:3.1+'
compile project(':loadingLibrary')
compile project(':welcomeLibrary')
// compile project(':licenceDialogLibrary')
compile project(':Bootstrap')
}
It used to work and then i wanted to add a new module and it all went downwards after that. Does anyone had this problem and solved it? I don't even know what is wrong..or how i made this.
The easiest way to solve this is to be delete a cache.
For Windows it's under C:\Users\Administrator\.gradle\caches
For Mac OSX it's ~/.gradle/caches
Try to execute the following command:
find ~/.gradle -type f -name "*.lock" | while read f; do rm $f; done
Updated my android studio to 0.5.1 just now and facing so many issues:
This is my build.gradle file:
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
}
}
apply plugin: 'android'
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
android {
compileSdkVersion 19
buildToolsVersion '19.0.3'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
signingConfigs {
release {
storeFile file('dsc.jks')
storePassword 'dscneo'
keyAlias 'dsc'
keyPassword 'dscneo'
}
}
buildTypes {
debug {
versionNameSuffix '-DEBUG'
}
beta {
versionNameSuffix '-BETA'
}
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.release
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/ASL2.0'
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile files('libs/gson-2.2.4.jar')
compile files('libs/gson-2.2.4-sources.jar')
compile files('libs/volley.jar')
compile files('libs/gson-2.2.4-javadoc.jar')
compile project(':HorizontalVariableListView')
compile files('libs/sugar-1.2.jar')
compile 'com.crashlytics.android:crashlytics:1.+'
compile project(':shopify_view_pager')
compile project(':shopify_smoothProgressBar_library')
compile files('libs/butterknife-4.0.1.jar')
compile project(':shopify_sliding_pane_library')
}
This is the error that is prompted:
Gradle 'shopping-app-android' project refresh failed:
Build script error, unsupported Gradle DSL method found: 'release()'!
Possible causes could be:
- you are using Gradle version where the method is absent
- you didn't apply Gradle plugin which provides the method
- or there is a mistake in a build script
Please help!
I have just started using Android Studio.
It seems like you're still running gradle plugin 0.8. See Migrating From 0.8 to 0.9