Class Not found when try to acces the class in the library of a android module from another Android module - android-studio-import

I have a Android library module (Common), which has a library dependency (com.android.support:multidex:1.0.1). Alongside "Common" module I have an Android module (Module1)ich requires "MultiDex" (located as dependency within the "Common" Library Module), but I get an error: android.support.multidex.MultiDex does not exist.
Common Library build.gradle:
apply plugin: 'com.android.library'
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
Module1 build.gradle:
dependencies {
compile project(':Common');
}
But in Module1 i am unable to use MultiDex

In your build.gradle you need to enable multidex as:
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Hope this helps..

Related

Gradle cannot find symbol class in Android Studio project

Gradle has trouble resolving a dependency in an Android Studio project. I have a library that has a dependency to a java module called "common". I have the dependency speficied in the buld.gradle (see below), however, I still get "cannot find symbol MyClass" when building. How can I fix this?
The line in error is the import that references the package in "common".
Building works fine with maven, but not with gradle.
This is the build.gradle of my lib.
apply plugin: 'com.android.library'
android {
compileSdkVersion 17
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 17
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':common')
}

failed to build tool version android

I tried to open an old project of mine in a freshly installed android studio (today), It gave me this error :
failed to find build tools revision 23.0.0 rc2
install build tools 23.0.0 rc2 and sync project
I looked for it in the internet and I tried to add this in the gradle file :
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
}
And it gave me another error:
gradle DSL method not found: 'android()'
possible causes:
the project may be using a version of gradle that does not contain the method.
gradle settings.
the build file may be missing a gradle plugin.
apply gradle plugin.
this is my gradle file :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
}
Right click on your project > Open Module Settings > Properties Tab, then change :
Compile Sdk Verion to API 23: Android 6.0
Build Tools Version 23.0.0
I checked the build tools version installed in my Android Studio and I have Android SDK Build-Tools rc3, Not rc2.
I changed it in build.gradle (Module App) to
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"}
After that it works.
Check if you have the same issue.
In your top level build.gradle you have to remove the android block
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
}
Just use:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
You have to use the android block, in the app/build.gradle where you should define something like:
apply plugin: 'com.android.application'
android {
compileSdkVersion XX
buildToolsVersion "XX.X.X"
defaultConfig {
minSdkVersion XX
targetSdkVersion XX
versionCode 1
versionName "1.0"
}
buildTypes {
release {
//......
}
}
}
dependencies {
//......
}
theres 2 gradle files
the one you have to modify is the one under this directory
APPLICATION NAME / APP / BUILD.GRADLE
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "PUT THE CODE YOU WANT HERE EX "23.0.0 r3""
defaultConfig {
applicationId "org.app.appname"
minSdkVersion 10
targetSdkVersion 22
versionCode 9
versionName "1.10.3"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:7.5.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:support-v4:22.2.1'
compile files('libs/volley.jar')
}
not the one which looks like these
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
In my case I tried everything and finally I had to do a simple change from this
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc2"
}
to this
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0" //DELETE rc2 AND SYNC PROJECT
}
It depends on which version of Android SDK Build-tools you have installed, you could check it via the SDK Manager, in my case I haven't the 23.0.0 rc2 installed but the 23.0.1, so you need to edit your app/build.gradle
for me it was then:
android {
compileSdkVersion 22
buildToolsVersion "23.0.1"
}

How to EXCLUDE an external library jar from Proguard in Android Studio?

The build.gradle of one of the modules in my project is pretty simple:
apply plugin: 'com.android.library'
android {
compileSdkVersion 8
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 8
targetSdkVersion 8
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg'
}
}
}
dependencies {
compile project(':timsvc')
compile files('libs/jsoup-1.8.2.jar')
}
However, when I build it, it fails to find symbols in the external library jsoup-1.8.2.jar.
Since timsvc is a module of mine, having its own build.gradle and proguard.cfg, I can control its minify level, and so I don't have any problems with it.
But I cannot do the same for jsoup-1.8.2.jar because it is an externally provided jar.
Is there a way to exclude it from Proguard in Android Studio?
If so, how do I accomplish that?
The best is to see the libraries documentations and readme page (like Github).
but in genneral you can add -keep options to your proguard configuration file for the classes in those external jars. For instance:
-keep class example.** { *; }

gradle error "Execution failed for task ':app:compileDebugJava' " while build groovy in android studio

I got a error while building groovy code in android studio.
the error msg is
C:\Users\Administrator\Desktop\lytest110\app\src\main\java\gzzhe\com\lytest110\MainActivity.java:41: error: can't find symbol
Log.d("lytest110", GroovyTest.getMsg());
^
symbol: parameter GroovyTest
possition: class MainActivity
1 error
FAILED
:app:compileDebugGroovy
FAILURE: Build failed with an exception.
my build.gradle is:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.2'
classpath 'me.champeau.gradle:gradle-groovy-android-plugin:0.3.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
the build.gradle in app directory:
apply plugin: 'com.android.application'
apply plugin: 'me.champeau.gradle.groovy-android'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "gzzhe.com.lytest110"
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile files('libs/groovy-2.4.0-beta-3-grooid.jar')
compile files('libs/android-support-v4.jar')
compile fileTree(include: ['*.jar'], dir: 'libs')
// compile 'com.android.support:support-v4:19.+'
}
I have put the groovy file into main/groovy/package/name directory.
the groovy is annotated with #CompileStatic.
This problem have puzzled me for several days.
From your error it seems like you are calling Groovy class with Java. According to the Android Groovy plugin readme. it says
Groovy sources must be found inside src/main/groovy. Note that the plugin follows the behavior of the Groovy plugin in Gradle, which means that if you want to be able to have Groovy classes referencing Java classes that themselves reference Groovy classes, then those Java classes must be found inside src/main/groovy too (this is called joint compilation).
So you just put your MainActivity.java to your ../main/groovy/package/name directory

Android Studio Google Maps API v2

i'm trying to use Google Maps API v2 in my project.
This is my environment:
OSX 10.9
Android Studio 0.3.2
min SKD 9 and compile SDK 14
Java 1.7.0_17
Testing on Nexus 7 4.3 with GooglePlayService 4.0.30
I get the following errors on the device. Android Studio don‘t note any errors:
11-05 07:44:33.888 2386-2386/myproject E/dalvikvm﹕ Could not find
class 'com.google.android.gms.maps.SupportMapFragment', referenced from method
myproject.activities.Maps.initMaps
11-05 07:44:34.052 2386-2386/myproject E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.common.GooglePlayServicesUtil
at myproject.activities.Maps.onResume(Maps.java:36)
The error point is clear: There are missing class files.
Here are the dependencies of my project:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 14
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 10
}
}
dependencies {
compile 'com.android.support:appcompat-v7:18.0.+'
compile 'com.android.support:gridlayout-v7:18.0.+'
compile 'com.android.support:support-v4:19.0.+'
compile 'com.android.support:support-v13:19.0.+'
compile 'com.google.android.gms:play-services:4.0.30'
}
In my opinion should be compile 'com.google.android.gms:play-services:4.0.30' enough.
So any suggestions what's missing ?
Greetz,
Moddus
I had the same problem.
When I changed the version to 'com.google.android.gms:play-services:3.1.36' my app started normally without any errors but the map was white.
Tried several diferent api keys and still don't know where the problem is...
edit: Finally I made my app to shows up the map by changing the classpath of the buildsctipt. I'm using Android Studio v.0.4 which comes with gradle:0.7 and I gess it has a problems for now with google play services. Here is my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
}
}
dependencies {
compile 'com.google.android.gms:play-services:3.1.36'
compile 'com.android.support:appcompat-v7:+'
}

Resources