I am researching the "instant run" feature in Android Studio. But it looks like it doesn't work with proguard. Is there anybody know why and how to get them work together?
My environment: Android Studio 2.0 Beta 4
My top level build.gradle
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-beta4'
}
}
allprojects {
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
jcenter()
}
}
The build.gradle for module:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 17
targetSdkVersion 23
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.1.1'
}
I can see some following "instatn run" tasks in gradle console with the above setting. And there is a yellow thunderbolt appear with the run button.
:TestIR:transformClassesWithInstantRunVerifierForDebug
:TestIR:transformClassesWithInstantRunForDebug
:TestIR:transformClasses_enhancedWithInstant+reloadDexForDebug
:TestIR:generateDebugInstantRunAppInfo
:TestIR:transformClassesWithInstantRunSlicerForDebug
Dexing C:\git\android\TestIR\build\intermediates\transforms\instantRunSlicer\debug\folders\1\5\slice_1 took 328
Dexing C:\git\android\TestIR\build\intermediates\transforms\instantRunSlicer\debug\folders\1\5\slice_0 took 340
Dexing C:\git\android\TestIR\build\intermediates\transforms\instantRunSlicer\debug\folders\1\5\slice_2 took 331
Dexing C:\git\android\TestIR\build\intermediates\transforms\instantRunSlicer\debug\folders\1\5\slice_5 took 321
Dexing C:\git\android\TestIR\build\intermediates\transforms\instantRunSlicer\debug\folders\1\5\slice_3 took 456
But if I set "minifyEnabled" to true, there is no "instant run" task in Gradle console any more, either the yellow thunderbolt button.
Is there anyway to get them work together?
According to this official Android developer page, Android Studio disables ProGuard when using Instant Run.
1.Go to 'run/debug configurations' remove your android application configuration
2.Recreate an android application configuration
3.Go to miscellaneous tab, uncheck 'force stop running application before launching activity'
Related
I am working on a project where I need to implement facebook login. For that purpose I followed the steps from the developer website as mentioned. But unfortunately getting build error after adding'com.facebook.android:facebook-android-sdk:4.1.0' in build.gradleas follows
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.facebook"
minSdkVersion 11
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
}
Error log which I am getting:
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not resolve com.facebook.android:facebook-android-sdk:4.1.0.
Required by: ExampleApp:app:unspecified
> No cached version of com.facebook.android:facebook-android-sdk:4.1.0 available for offline mode.
> No cached version of com.facebook.android:facebook-android-sdk:4.1.0 available for offline mode.
Please help me to resolve this issue which I am facing right for a couple of days. I am really helpless and stuck up with the solutions. Any kind of suggestions would be much useful to fix my issue.
Your log gives the answer:
No cached version of com.facebook.android:facebook-android-sdk:4.1.0 available for offline mode.
Gradle is in offline mode, so it cannot download a new version of your library.
Go to Preferences > Build, Execution, Deployment > Build Tools > Gradle
and disable "Offline work".
Preferences can be accessed from here:
You do not need repositories in this gradle file as you should have one "global" build.gradle so remove this entry from module's grade file. And you should also check what repository is set there as it should be jcenter() not mavenCentral() as the latter is replaced with jcenter() for some time now.
allprojects {
repositories {
jcenter()
}
}
Gradle gets stuck when I try to build on the task [:android:generateDebugSources].
I've left it running for hours without a successful build.
I've tried it in Android Studio 1.0.0, 0.8.1, with Gradle versions 2.1.1, 1.12, 1.14, Android plugin versions 0.12.+ and 0.14.4 using the default wrapper as well as local distributions. I've reinstalled Android Studio and rebooted without any luck. Also tried File --> invalidate caches/Restart.
Here is my android package's build.gradle:
buildscript {
repositories
{
maven { url 'https://maven.fabric.io/repo' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'android'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/repo' }
}
android {
compileSdkVersion 21
buildToolsVersion '21.1.1'
defaultConfig {
minSdkVersion 11
targetSdkVersion 21
versionCode 13
versionName "onBoarding"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/android-query-full.0.26.8.jar')
compile files('libs/gson-2.3.jar')
compile 'com.android.support:appcompat-v7:21.+'
compile 'com.android.support:support-v4:21.+'
compile 'com.android.support:recyclerview-v7:21.+'
compile 'com.google.android.gms:play-services:6.1.71'
}
And then my project-level gradle.build file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Any advice greatly appreciated.
Got it! Changing the buildToolsVersion from 21.1.1 to 20 yielded a successful build.
You can also, just install the correct version of the tools.
I know this is an old question, but I spent a lot of time in this problem and read at least 30 answers until I found out what was hapenning.
I constantly got a message that another aplication was locking a file that Android-Studio needed to complete gradle building. Finally, I found out that it was Avast. So I simply deactivated it and the build finished successfully, but it still took a long time (about 10 minutes).
Tried below option and it worked!
Add below properties to your .gradle file
org.gradle.daemon=true
org.gradle.parallel=true
Set SLAVE_AAPT_TIMEOUT environment variable to 30 in windows and restart your system.
Second solution credit goes to semuzaboi.
I install the Android Studio and build a new project, but the automatic generated code show lots of "cannot resolve" errors like "cannot resolve symbol app" in the code "import android.support.v7.app.ActionBarActivity;"
The onCreate and setContentView Method cannot be resolved too
My Android Studio version is 0.4.2 , gradle version is 1.9
my build gradle is:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
You can do "File" -> "Invalidate Caches...", and select "Invalidate and Restart" option to fix this.
Well that worked for me.
Open your SDK Manager (you can find it in toolbar), and download
Android Support Repository and Android Support Library (you can find them in extras).
Google Repository and Google Play Service
Then sync your project with your gradle files (there is a button in toolbar).
After Upgrading to version 0.4.0 of Android Studio, I have started getting the following error when compiling my project:
A problem occurred configuring project ':muve'.
> Could not resolve all dependencies for configuration ':muve:classpath'.
> Could not resolve com.android.tools.build:gradle:0.7.+.
Required by:
MUVE:muve:unspecified
> Failed to list versions for com.android.tools.build:gradle:0.7.+.
> Could not list versions using M2 pattern 'http://repo1.maven.org/maven2/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]'.
> Could not GET 'http://repo1.maven.org/maven2/com/android/tools/build/gradle/'.
> Network is unreachable: connect
My build.gradle file is:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 11
targetSdkVersion 18
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
I am at a loss on how to resolve the issue. Any help would be highly appreciated.
Thanks
It's a networking problem, somewhere between you and Maven Central. Try again after a while, perhaps with --refresh-dependencies. I've you've successfully built with the same dependencies before, you can also try an offline build (-o).
Try this and check whether your studio can make connection successful with mention maven repository in error.
Go to File > Settings > HTTP proxy , select auto detect proxy settings just for test.
In my case, I was using an HTTP proxy, and this was my .gradle/gradle.properties :
systemProp.http.proxyHost=10.23.201.11
systemProp.http.proxyPort=3128
I changed it to HTTPS, even though I was using HTTP
systemProp.https.proxyPort=3128
systemProp.https.proxyHost=10.23.201.11
When I hit Sync, Android Studio Popped this:
Android Studio Pop up
Uncheck the HTTPS proxy and then OK.
I am trying to include the library Slik and Cards-UI in my app, I'm using android studio and gradle to build. The app builds fine without this but adding the dependency make the build fail. Looking at the debug log of the build it doesn't seem to be looking in the local repo for the arr file. I can see the files are there and I have followed the tutorial on the github wiki page for the install and that works fine. The error is:
A problem occurred configuring project ':climbtrack'.
> Could not resolve all dependencies for configuration ':climbtrack:_debugCompile'.
> Could not find com.afollestad.cardsui:library:1.0-SNAPSHOT.
Required by:
ClimbTrack:climbtrack:unspecified
> Could not find com.afollestad.silk:library:1.0-SNAPSHOT.
Required by:
ClimbTrack:climbtrack:unspecified
Here is my build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
repositories {
mavenLocal()
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
compile 'com.afollestad.cardsui:library:1.0-SNAPSHOT'
compile 'com.afollestad.silk:library:1.0-SNAPSHOT'
}
The google play services dependency works fine and is found from the maven central repo as expected.
Any ideas anyone?
Thanks
This is bug https://code.google.com/p/android/issues/detail?id=63908
If you look at comment #3 in that bug, there's a workaround. Try it and see if it helps:
This appears to be a bug in Gradle 1.9 with local Maven repositories.
See https://plus.google.com/109385828142935151413/posts/hF7W59uZ7rX
The workaround for now is to use
maven { url "${System.env.HOME}/.m2/repository" }
instead of mavenLocal()
In Android Studio 0.4.6 using mavenLocal works fine:
repositories {
mavenCentral()
mavenLocal()
}
Check and configure your Maven installation on Preferences >> Maven to ensure it points to your local repository.
I hope this update helps newcomers.