Android Studio: error: cannot find symbol variable AudioSystem - android

my project has an error when running is :
error: cannot find symbol variable AudioSystem
I have made sure that my code had imported :
import android.media.AudioSystem;
and the SDK version 19 has been installed
, and my build.Gradle information as below:
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
defaultConfig {
minSdkVersion 19
targetSdkVersion 23
How do I overcome this error? Thanks
When I typed the letter "A" after "import android.media.",the Auto list didn't show AudioSystem to let me to select.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
tasks.withType(JavaCompile) { options.encoding = "UTF-8" }
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile files('3rd_party_library/dom4j-1.6.1.jar')
compile files('3rd_party_library/jaxen-1.1-beta-7.jar')
compile files('3rd_party_library/core-3.2.1.jar')
compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
}
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
defaultConfig {
applicationId "com.test.smmitest"
minSdkVersion 19
targetSdkVersion 23
versionCode 20170713
versionName "4.5.6"
}
dexOptions {
javaMaxHeapSize "4g"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
signingConfigs {
release {
}
debug {
storeFile file("Keystore/debug.keystore");
storePassword ("android");
keyAlias = "androiddebugkey";
keyPassword = "android";
}
}
buildTypes {
release {
}
debug {
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
}

Related

Error:Cause: com.android.build.gradle.managed.ProductFlavor$Impl

When Android studio does Gradle sync, it has the following error message:
Gradle "MyApplication2" project refresh failed
Error:Cause: com.android.build.gradle.managed.ProductFlavor$Impl
After searching, still cannot get rid of it. Could you help? Thanks!
My project build.grade:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.6.0-alpha3'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My module build.gradle:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
applicationId = "SamplePlayer"
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = "1.0"
ndk {
moduleName "SamplePlayer"
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
jni.srcDirs = []
}
}
task ndkBuild(type: Exec) {
commandLine 'ndk-build', '-C', file('src/jni').absolutePath
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
android.lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-android.txt'))
}
}
}
dependencies {
compile fileTree(dir: '../Jar', include: '*.jar')
compile fileTree(dir: 'libs', include: '*.jar')
}
My other module build.gradle:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
applicationId = "com.example.cfcalex.myapplication2"
minSdkVersion.apiLevel = 22
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = "1.0"
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-android.txt'))
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}

unable to fix the project ,gradle issue

enter code hereunable to fix the project , new to android studio , need help fixing gradle my gradle file ,happening when i import projects from eclipse, exporting done fine
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
compile project(':ksoap2-android-assembly-2.5.8-jar-with-dependencies')
}
android {
compileSdkVersion 22
buildToolsVersion "23.0.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
and the error i am getting is
Error:Configuration with name 'default' not found.
changed code
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.package.name"
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
compile project(':ksoap2-android-assembly-2.5.8-jar-with-dependencies')
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.package.name"
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
Add the defaultConfig into the android block
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.package.name"
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
EDIT 1 : The android part of your gradle file should be inside the applications build.gradle not in the projects root gradle
There are two gradle files
Here is a sample Root Project 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.0.0-alpha1'
// 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
}
Sample Module Gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.package.name"
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.android.support:cardview-v7:23.1.1'
}

Too much methods in main dex

i had modified the build.gradle file for configuring multidex also i had a study in the official documentation ,but the new problem is "Too much of methods in main dex" how to reduce the methods in main dex
build.gradle
apply plugin: 'com.android.application'
android {
defaultConfig {
compileSdkVersion 23
buildToolsVersion '23.0.1'
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion 23
// Enabling multidex support.
multiDexEnabled true
}
dexOptions {
jumboMode = true
preDexLibraries = false
javaMaxHeapSize "2048M"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
productFlavors {
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
i think you are using more than one dependencies with same package name like compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.google.android.gms:play-services-wearable:7.5.0'

Build script error, unsupported Gradle DSL method found: 'release()'! when uograded to 0.5.1

Not able to solve this error, I have updated Android studio. gone throungh other this solutions but not worked for me, please help..
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
Gradle settings
Gradle version - 0.9
Main gradle.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
}
Project Gradle file
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 17
buildToolsVersion '18.0.1'
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
signingConfigs {
release {
storeFile file('dsc.jks')
storePassword 'dscneo'
keyAlias 'dsc'
keyPassword 'dscneo'
}
}
buildTypes {
debug {
versionNameSuffix '-DEBUG'
}
beta {
versionNameSuffix '-BETA'
}
release {
signingConfig signingConfigs.release
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:3.1.36'
compile 'com.android.support:appcompat-v7:18.0.+'
compile 'com.android.support:support-v4:+'
compile files('libs/libGoogleAnalyticsServices.jar')
compile files('libs/signpost-commonshttp4-1.2.1.1.jar')
compile files('libs/signpost-core-1.2.1.1.jar')
compile files('libs/gson-2.1.jar')
compile project(':facebook')
compile project(':TabIndicatorLibrary')
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile project(':VerticalViewPager')
compile files('libs/universal-image-loader-1.9.1.jar')
compile files('libs/universal-image-loader-1.9.1-sources.jar')
compile files('libs/twitter4j-core-3.0.5.jar')
compile files('libs/HockeySDK-3.0.1.jar')
}
Facebook SDK gradle file
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
android {
compileSdkVersion 17
buildToolsVersion "18.0.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
Other library project gradle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
android {
compileSdkVersion 16
buildToolsVersion '18.0.1'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
one more library project gradle file.
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
versionCode 1
versionName "1.0"
}
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
In your last file (library) you have the release block inside the android block.
The DSL for the library projects is now the same as for the application projects
In particolar you have to put the release block inside the buildTypes.
android {
buildTypes {
release {
}
}
Also I suggest you use buildToolsVersion '19.0.x' for all your gradle files.
You can put it in your build.gradle in root folder.
ext {
compileSdkVersion = 19
buildToolsVersion = "19.0.3"
}
Then in each build.gradle file you can use:
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

Android, Gradle. How to build application and run tests from test application

I have android project and android test project inside it, located under folder tests. Structure of these project is eclipse like
+-src
| - res
| - libs
| - tests
|.....
I use gradle. All i want is to build app, run unit tests and get reports of them. But i don't understand how to do it right. I'm created build.gradle file in root folder
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 18
testPackageName "ua.cooperok.stringcalc.tests"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
unitTest {
java.srcDir file('tests/src')
resources.srcDir file('tests/res')
}
}
configurations {
unitTestCompile.extendsFrom runtime
unitTestRuntime.extendsFrom unitTestCompile
}
dependencies {
unitTestCompile files("$project.buildDir/classes/release")
}
task unitTest(type:Test){
description = "Run unit tests..."
testClassesDir = android.sourceSets.unitTest.output.classesDir
classpath = android.sourceSets.unitTest.runtimeClasspath
}
build.dependsOn unitTest
}
But when i run gradle build i got error
Could not find property 'output' on source set unit test.
Also, as i understand, to get reports i need to apply plugin "android-reporting", but when i do this i got error
Cannot add extension with name 'android', as there is an extension already registered with that name.
Should i do it like this, or i must create new gradle.build file in my test application project?
UPDATE
I fixed error with output, and made gradle build successful, but I don't understand what's goind on. I purposely failed my test, but gradle build is still successful.
What I've done:
1. I moved task unitTest from android section to root, after that, my test project began to compile, but there is an error 'packackage android.test not found'
2. To fix that error I added to classpath path to android sources, so after that gradle build was successful, but realy I don't understand why it's always successful even when test fails
And still I don't understand how to get reports from test
This is my new build.gradle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 18
testPackageName "ua.cooperok.stringcalc.tests"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
sourceSets {
main {
manifest.srcFile file('AndroidManifest.xml')
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
}
sourceSets {
unitTest {
java.srcDirs = ['tests/src']
resources.srcDirs = ['tests/src']
}
}
configurations {
unitTestCompile.extendsFrom runtime
unitTestRuntime.extendsFrom unitTestCompile
}
dependencies {
unitTestCompile files("$project.buildDir/classes/release")
unitTestCompile 'junit:junit:4.11'
compile fileTree(dir: 'libs', include: '*.jar')
}
task unitTest(type:Test, dependsOn: assemble) {
description = "run unit tests"
testClassesDir = sourceSets.unitTest.output.classesDir
classpath = files("$System.env.ANDROID_HOME/sources/android-18")
//actualy I didn't get any report
getReports().getJunitXml().setOutputPerTestCase(true)
}
build.dependsOn unitTest
I found solution. I was dissapointed by few topics, and thought that i need to create separate task for unit tests. In fact it was prety easy.
I didn't change my project structure, just build.gradle file. To build application i run
gradle clean connectedCheck build
connectedCheck runs unit tests from my test project and if some test fails - gradle build will fails too
Here final version of it
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 18
testPackageName "ua.cooperok.stringcalc.tests"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
sourceSets {
main {
manifest.srcFile file('AndroidManifest.xml')
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest {
java.srcDirs = ['tests/src']
manifest.srcFile file('tests/AndroidManifest.xml')
resources.srcDirs = ['tests/src']
res.srcDirs = ['tests/res']
assets.srcDirs = ['tests/assets']
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
//Signing apk
if(project.hasProperty("signingPropertiesPath")) {
File propsFile = new File(System.getenv('HOME') + "/" + project.property("signingPropertiesPath"))
if(propsFile.exists()) {
Properties props = new Properties()
props.load(new FileInputStream(propsFile))
//loading keystore properties
signingConfigs {
release {
storeFile file(propsFile.getParent() + "/" + props['keystore'])
storePassword props['keystore.password']
keyAlias props['keyAlias']
keyPassword props['keyPassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
}
}

Categories

Resources