Can't use some of L SDK features - java

I'm trying to use the new Activity transitions in the new SDK.
I tried this line:
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
But the problem is that Window doesn't include FEATURE_CONTENT_TRANSITIONS.
I also tried this line:
getWindow().setExitTransition(new Explode());
And Explode class doesn't exist...
I already set my project to be compiled with L SDK (android-L) and use the new SDK tools (20.0.0)
build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-L'
buildToolsVersion '20.0.0'
defaultConfig {
applicationId 'com.tester'
minSdkVersion 'L'
targetSdkVersion 'L'
versionCode 1
versionName '1.0'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:support-v4:+"
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}

seems like you are not including the L SDK library in your build path.
Are the libraries listed as dependency of your project?

Try File -> Invalidate Caches / Restart.
If that doesn't work, you can try deleting ~/.AndroidStudioBeta (or ~/.AndroidStudioPreview, whichever you are using). It will clear all your settings so be prepared for that, but this solved the issue in my case.
For Mac, clear:
~/Library/Application Support/AndroidStudioBeta
~/Library/Caches/AndroidStudioBeta
~/Library/Logs/AndroidStudioBeta
~/Library/Preferences/AndroidStudioBeta

Related

Android databinding tests fails in Module NoClassDefFoundError

I could not able to run the local unit tests in Module which is using android Data binding library.
First let me tell about the project structure how its configured.
project
| app
-MainLauncherActivity
| myLibrary
-CommonModuleActivity
I have created a new project, after that have added a new module "myLibrary".
the main "app" depends on "myLibrary" module. I have added one activity in "myLibrary" it supports databinding. I called module specific activity from main "app" activity on button click in it. it just works, could able to run the app.
But, Getting the below errors when i add a test case for the Module Activity.
AndroidStudio : 2.3
Gradle build tools version 2.3.0 -->
Error:java.lang.NoClassDefFoundError: android/databinding/DataBinderMapper
Gradle build tools version 2.2.3 -->
Error:java.lang.NoClassDefFoundError: android/databinding/ViewDataBinding
PROJECT IDE SCREENSHOT
project root 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:2.3.0'
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
below is "app" build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.bindingtest"
minSdkVersion 21
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'
}
}
dataBinding {
enabled true
}
}
dependencies {
compile 'com.android.support:appcompat-v7:25.1.0'
//compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
testCompile 'junit:junit:4.12'
compile project(':mylibrary')
}
below myLibrary build.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
minSdkVersion 21
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'
}
}
dataBinding {
enabled 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:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.10.19"
}
LibraryActivity:
public class MyLibraryActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityMyLibraryBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_my_library);
//set data to binding
}
}
Corresponding test case can be found in the attached screenshot.
Could some one tell me what am i doing wrong here to get it tested.
APP IS WORKING FINE, ONLY UNIT-TESTS ARE FAILING!!!
I know it's too late to answer that question , But I say to friends who may face this problem.
Any time You used to dataBinding and at unit test faced with NoClassDefFoundError
first add this lines in build.gradle(Module)
testOptions {
unitTests{
isIncludeAndroidResources=true
}
}
then add this library to the dependencies at build.gradle(Module)
kaptTest("androidx.databinding:databinding-compiler:7.0.4")
I think this is a known issue which you can review here. I've been tracking this issue since February. Doesn't seem to be fixed yet.
added android.enableExperimentalFeatureDatabinding=true in gradle.properties . According to the name of this property, I think it could work for sometimes but not always, you can try.

Android google play services duplicate entry causing issue with productFlavors

Creating an app that has two productFlavors paid and free. Now since I use Google play services for Ads, its giving a very hard time throwing errors one by one, I've been searching on this one for the whole day, and it seems the root cause is the difference in version of play services specified in my gradle.
At the moment, this is the error I obtain:
Error:Execution failed for task
':app:transformClassesWithJarMergingForPaidRelease'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry:
com/google/android/gms/internal/zzkb.class
Answers to similar question point to cross check if similar .jars exist. However I tried my best and I am helpless.
This is my app level build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
lintOptions {
abortOnError false
}
defaultConfig {
applicationId "com.udacity.gradle.builditbigger"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
free {
applicationId = "com.udacity.gradle.builditbigger.free"
}
paid {
applicationId = "com.udacity.gradle.builditbigger.paid"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// Added for AdMob
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.firebase:firebase-ads:9.0.2'
compile project(path: ':backend', configuration: 'android-endpoints')
compile project(path: ':joketeller')
}
apply plugin: 'com.google.gms.google-services'
And this is my top level build.gradle file :
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.google.gms:google-services:2.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Desperate to fix this, any help will be highly appreciated, Thanks!

Android gradle :app:packageDebug FAILED: class org.bouncycastle.asn1.ASN1Primitive overrides final method equals

I'm new to Android and I can't get my first app to run. Whenever I try, it's throwing this error:
Android gradle :app:packageDebug FAILED: class org.bouncycastle.asn1.ASN1Primitive overrides final method equals.
I googled it and I found many questions there. As many said, this problem is probably due to the fact that I have multiple dependencies on BouncyCastle in my project. I tryed to remove the .gradle folder both in my project and in my local folder so I could download again the jars from the repository but nothing has changed. I also double checked that my JAVA_HOME is set and it's pointing to a 1.7 version. I tryed to gradle :app:clean and gradle :app:dependencies to see if I was missing something but still... I can't see any dependency from BouncyCastle... Can anybody help me?
Also, this problem occured without me changing any code... The app successfully worked yesterday and now is giving me this error... I don't get it. Thank you.
EDIT
gradle.build
Top-level:
// 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.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Module app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.aurasphere.provaactionbar"
minSdkVersion 11
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:7.0.0'
compile project(':volley')
compile files('libs/gson-2.2.2.jar')
}
Module volley:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.+'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 19
buildToolsVersion = '21.1.0'
}
apply from: 'rules.gradle'
rules.gradle for module volley:
apply plugin: 'com.android.library'
I've solved this problem myself just by changing the JDK I was using from x32 to x64 and now is compiling correctly.

Gradle DSL method not found: 'compile()' error

I promise I have looked at all the answers provided.
1) I wanted to use DialogFragment and developers guide suggested to install Support libraries. I agree I did not go through and pick and choose and I asked it to install all 22 Android support libraries (Android support repository already looked installed).
2) Ensured that the project level build.gradle does not have any compile under dependencies. Only the Module: app level build.gradle has the compile.
3) When I attempted to add the compile "com.android.support:support-v4:18.0.+" to the app module build.gradle, it reds on me because the target sdk is 22. So, I go to change it to 18. No dice.
4) Same annoying error: Gradle DSL method not found: compile():The project may be using a version that does not contain the method: open Gradle wrapper.properties OR The build file may be missing a plugin : Apply Gradle plugin
5) I applied every possible plugin.
Any help would be greatly appreciated.
Project level build.gradle:
// 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'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
App level build.gradle:
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias '******'
keyPassword '*******'
storeFile file('********************')
storePassword '********'
}
}
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "project.sample.com.blatest"
minSdkVersion 8
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
<!-- begin snippet: js hide: false -->
<!-- language: lang-html -->
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias 'dialogkey'
keyPassword 'changeme'
storeFile file('C:/Users/ybxk021/.android/default.keyset')
storePassword 'blabla123'
}
}
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "project.sample.com.dialogtest"
minSdkVersion 8
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:support-v4:22.2.0'
}
}

Compile time only dependency and ProGuard using Gradle

I am building an Android library with Gradle and I have a compile time only dependency.
I am using Gradle 0.9+ so if I do
android.libraryVariants.all { variant ->
variant.packageLibrary.exclude( 'libs/libA.jar' )
}
it works and libA.jar is not packaged in my final aar.
However, if I turn ProGuard to on, this does not work and libA.jar is getting packaged.
I have also excluded this jar from obfuscation by adding
-keep class com.libA.** { *; }
to my proguard-rules.txt but it doesn't make any difference.
I can see that the proguardRelease task gets executed before all the packageRelease tasks, however I am not really sure if I can do anything.
This is my whole build file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
android.libraryVariants.all { variant ->
variant.packageLibrary.exclude( 'libs/libA.jar' )
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:20.0.0'
}
Is there any way to compile against a jar but exclude it from the final package without having to turn ProGuard off?
I just recently came back to this and found a workaround, so I thought I would share:
I am now adding the 'libs' folder as a local repository, so my build file looks something like that (I have also updated the Gradle version):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
}
}
apply plugin: 'com.android.library'
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
dependencies {
compile ':libA'
compile 'com.android.support:support-v4:20.0.0'
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
The dependency is resolved fine and is not packaged in the final aar.
Also, I am not including anything extra in the proguard file.

Categories