I recently (3 days ago) started learning Android Studio. I bought an Eclipse game project to play with, but I am getting errors. And when I fix that error, I get a new error.
The current one that I can't seem to fix is:
Error:(2, 0) Could not find method defaultConfig() for arguments
[build_2ttwbw07u5v666j5nx2ciclk3$_run_closure1#5ac759e5] on project
':app' of type org.gradle.api.Project. Open
File
My build.gradle (Module: App):
defaultConfig {
applicationId "com.getemplate.catadventure"
minSdkVersion 14
targetSdkVersion 26
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [] //disable automatic ndk-build call
}
ndk {
moduleName "player_shared"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
dexOptions {
preDexLibraries = false
}
}
dependencies {
compile 'com.google.android.gms:play-services:+'
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/support-v4-19.0.1.jar')
}
Anyone know why I am getting the error?
Here's a screenshot:
Thank you very much for your time and assistance in this matter.
This is because you didn't add code for android application plugin which is apply plugin: 'com.android.application'. You also need to move the defaultConfig inside the android like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.3"
defaultConfig {
...
}
}
dependencies {
...
}
Related
I want build my project from AndroidStudio into my phone, but when run button in Android Studio. show me this error :
Error:Execution failed for task ':app:compileDebugNdk'.
> Error: Your project contains C++ files but it is not using a supported native build system.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental.
Build.Gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.companyname.gamename"
minSdkVersion 14
targetSdkVersion 23
ndk {
moduleName "player_shared"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:+'
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/support-v4-19.0.1.jar')
}
How can i fix it?
paste below code in your build.gradle(Module:app)
sourceSets {
main {
jni.srcDirs = []
}
}
buildTypes{
}
Paste this in build.gradle above buildTypes{}
sourceSets {
main {
jni.srcDirs = []
}
}
buildTypes{
}
I want to use OpenCV4Android in Android Studio. I downloaded OpenCV for Android from this link:
http://opencv.org/downloads.html
But, when I try to import it, I get different errors in Camera2Renderer.java like, Cannot resolve symbol 'camera2', Cannot resolve symbol 'CameraDevice', Cannot resolve symbol 'Size', and Cannot resolve symbol 'CaptureRequest'.
I have tried both methods available here:
OpenCV in Android Studio
http://answers.opencv.org/question/14546/how-to-work-with-opencv4android-in-android-studio/
But, I get the same error.
Can anyone please tell me how to solve this error to be able to use openCV?
Thank you.
I faced the same issue while configuring OpenCV SDK with Android Studio.
I am using the latest SDK build of OpenCV : OpenCV-3.1.0-android-sdk
Please ensure that you have configured your build.gradle scripts.
Build.gradle(Module: app) -->
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.example.dev.opencvapp"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLib/'] } }
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile project(':openCVLibrary310')
}
Build.gradle(Module: openCVLibrary310) -->
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
After doing this you should be able to build the app with out any errors.
I hope I helped you!!
I'm a newbie with gradle and I'm having a dependecy problem. I have the follow project structure:
-MyApp
-MyAppLibrary
-MyAppPro
-MyAppFree
-ThirdPartyLibraryWrapper
--libs\ThirdPartyLibrary.aar
Both MyAppPro and MyAppFree depend on MyAppLibrary, which depends on ThirdPartyLibraryWrapper. As the name suggests, ThirdPartyLibraryWrapper is a wrapper on an external library, namely ThirdPartyLibrary.aar.
This is my configuration:
build.gradle MyAppPro
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example"
minSdkVersion 8
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
dependencies {
compile project(':MyAppLibrary')
}
build.gradle MyAppLibrary
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
dependencies {
compile project(':ThirdPartyLibraryWrapper')
compile 'com.squareup.picasso:picasso:2.5.2'
}
build.gradle ThirdPartyLibraryWrapper
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name: 'ThirdPartyLibrary-0.1.0', ext: 'aar')
compile "com.android.support:support-v4:22.0.0"
compile fileTree(dir: 'libs', include: 'volley.jar')
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
}
When gradle sync completes, I have got this error:
MyApp/MyAppFre/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
MyApp/MyAppLibrary/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
MyApp/MyAppPro/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
Can someone help me figure out where is the issue?
The other projects are seeing that the :ThirdPartyLibraryWrapper project depends on an artifact called ThirdPartyLibrary-0.1.0:aar. Java (and Android) libraries do not bundle their own dependencies together - instead, they simply publish a list of their dependencies. The consuming project is then responsible for loading not only the library it directly depends on, but all of the libraries that library depends on.
The net effect of this is that :MyAppFree is loading in :ThirdPartyLibraryWrapper, then seeing that :ThirdPartyLibraryWrapper depends on ThirdPartyLibrary-0.1.0:aar and so thus trying to load that in as well. However, :MyAppFree doesn't know where ThirdPartyLibrary-0.1.0:aar lives.. and so it fails.
The solution will be to place similar repositories blocks in all your other projects. Try this:
repositories {
flatDir {
dirs project(':ThirdPartyLibraryWrapper').file('libs')
}
}
Using the project(...).file(...) method will free you from having to hardcode paths, and will instead use the Gradle DSL to resolve the filesystem path by looking up the project and having it do the resolution dynamically.
I am new to Android Studio and was just trying to import my eclipse project. i am trying to resolve this issue for quite a while now but unable to.
I have a mainactivity project which uses mmany other libraries staggeredgridview, devsmart, google maps and appcompactv7. I am getting following 2 errors.
Note: mainactivity project is the one which i am working on and uses other external libraries.
Error:(7, 5) uses-sdk:minSdkVersion 8 cannot be smaller than version 9 declared in library B:\Android Studio Projects\mainActivity\build\intermediates\exploded-aar\com.google.android.gms\play-services\6.5.87\AndroidManifest.xml
Suggestion: use tools:overrideLibrary="com.google.android.gms" to force usage
:mainActivity:processDebugManifest FAILED
Error:Execution failed for task ':mainActivity:processDebugManifest'.
Manifest merger failed with multiple errors, see logs
build.gradle of mainactivity
apply plugin: 'com.android.application'
android {
compileSdkVersion 17
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.staggeredgridviewdemo"
minSdkVersion 8
targetSdkVersion 16
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':devsmartAndroid')
compile project(':staggeredGridViewmaster')
compile 'com.google.guava:guava:16.0.1'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:appcompat-v7:19.1.0'
compile files('libs/commons-codec-1.6.jar')
}
build.grade for devsmart
apply plugin: 'com.android.library'
android {
compileSdkVersion 14
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 4
targetSdkVersion 4
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile files('libs/CWAC-SackOfViewsAdapter.jar')
compile('com.android.support:appcompat-v7:19.1.0') {
// really use 19.1.0 even if something else resolves higher
force = true
}
}
build.gradle for sttageredgridview
apply plugin: 'com.android.library'
android {
compileSdkVersion 17
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile('com.android.support:appcompat-v7:19.1.0') {
// really use 19.1.0 even if something else resolves higher
force = true
}
}
Just edit minsdk of your build.gradle of mainactivity to 9 :
defaultConfig {
applicationId "com.example.staggeredgridviewdemo"
minSdkVersion 9 // changed line
targetSdkVersion 16
}
Note : Also did the same for other libs if there minsdk is small then 9
Please open your manifest file and write the bellow code it will work
<uses-sdk tools:overrideLibrary="com.google.android.gms"/>
and add the list of libraries for uses-skd separated by comma
Go to all the manifest files or build.gradle files of all the projects and make the minSDKversions the same.8 for instance.
I am trying to learn android in android studio.Now i imported an eclipse project in android studio and now while trying to run it it is not building.Some problems in gradle may be..
Error:Execution failed for task ':app:processDebugManifest'.
Manifest merger failed : uses-sdk:minSdkVersion 8 cannot be smaller than version L declared in library com.android.support:support-v4:21.0.0-rc1
my build.gradle
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "com.example.practise"
minSdkVersion 8
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:+'
compile 'com.android.support:gridlayout-v7:+'
}
Can anyone help me to find out the problem??
Change your dependencies
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile 'com.android.support:gridlayout-v7:19.1.0'
}
Using the +, you are getting the last release.
Currently the last release is the compile 'com.android.support:support-v4:21 and it has a minSdk='L' because it is a preview release.
Use it only to test the android 'L' preview.
Try editing the following line to your Android Manifest file, like so:
dependencies {
compile 'com.android.support:support-v4:21+'
}
Then your project should build.
Change your dependencies in app/build.gradle to lower version
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.eusecom.snowsmsden"
minSdkVersion 16
targetSdkVersion 20
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:20.+'
compile 'com.android.support:appcompat-v7:20.+'
}