Android Studio builds two applications for the same project simultaenously - android

I'm making an app using Android Studio v0.5.9, which has a library project as a dependency. But, every time I run the project two apks having the same name and icon, are deployed to my device. The first apk(app) contains my main module, whereas, the second one is the library project itself. However, when I run the same project from Eclipse, only one apk is deployed and it works perfectly.
Here are some screenshots of the problem -
First App(My module) -
Second App(library project) -
top-level build.gradle file -
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
}
}
main module build.gradle file -
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.3'
defaultConfig {
packageName 'com.Swap.Rooms'
minSdkVersion 8
targetSdkVersion 19
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:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile 'com.android.support:appcompat-v7:19.+'
compile project(':lib')
}
library project build.gradle file -
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
packageName "com.jfeinstein.jazzyviewpager"
minSdkVersion 4
targetSdkVersion 17
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:+'
compile files('libs/nineoldandroids-2.4.0.jar')
}
settings.gradle -
include ':app'
include ':lib'
Please help me to fix this. Thanks in advance!!

Maybe this will be helpful for others.
Gradle is doing manifest merge for library projects as well. So issue was to keep AndroidManifes.xml unchanged from library. It had application node for demo purposes and this node was successfully merged to main AndroidManifest.xml.
I'm going to submit issue to Google since I think it should prevent or warn about such situation.

Eugen Martynov answer is correct but i decided to reiterate what he said in layman's terms.
Go through your libraries and check their AndroidManifest.xml. One of them should have an <application> tag in it. Remove the tag and the double app problem will be solved.

The specific element in the ApplicationManifest.xml, that affects creating multiple launcher icons is the <intent-filter> containing <category android:name="android.intent.category.LAUNCHER"/>. Removing this <intent-filter> will give you control over the number of launcher icons. You can read a bit more elaborate SO answer here.

It took me time to realize where the issue was.But finaly worked out for me.
The issue is with the Manifest.xml file. It means that you have two activities set as LAUNCHER.
just remove the code simmilar to the one below from the activity that is not your LAUNCHER
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

Related

Toolbar: IllegalStateException - configure your build for VectorDrawableCompat

I'm using Android Studio 2.1.2. I started a new project with minSdkVersion as 19. My activity extends AppCompatActivity. The project starts with an empty activity using a fragment.
When previewing content_main.xml with API 24, all is good. when previewing API 19, I get the following rendering problem:
The following classes could not be instantiated:
- android.support.v7.widget.Toolbar
java.lang.IllegalStateException: This app has been built with an incorrect configuration. Please configure your build for VectorDrawableCompat
I have added every thing I found relevant to the gradle (2 files):
classpath 'com.android.tools.build:gradle:2.1.2'
vectorDrawables.useSupportLibrary = true
buildToolsVersion "24.0.1"
compile 'com.android.support:appcompat-v7:24.1.1'
compile "com.android.support:support-v4:24.1.1"
compile 'com.android.support:design:24.1.1
But still the error appears. I've found a lot of answers on internet. But none helped. Is there a problem using the new toolbar with API 19?
This worked well for me
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.app"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
generatedDensities = []
}
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Notice this in the above code:
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}
and
generatedDensities = []
from this google Issue
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
check this issue for more help.
UPDATE
configured your app build.gradle file as follows
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
}
Source
Age Of Vectors
Firstly, there are two types of gradle files.
build.gradle(Project: ProjectName)
build.gradle(Module: app)
For more information on these two files, go through this answer.
Coming to your question,
I've found a lot of answers on the net but none helped. I'm using
Android Studio 2.1.2, my activity extends AppCompatActivity and added
to the gradle (2 files) every thing I found relevant: but still the
error appears.
From whatever you have posted, it seems like you didn't add right things at right places.
You shouldn't place your application dependencies in build.gradle(Project: ProjectName) - Android Studio says,
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Hence, replace your dependencies in build.gradle(Project: ProjectName) with below
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
Replace your dependencies in build.gradle(Module: app) with below
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
}
After doing as mentioned above, you will see a "Sync Now" option on the Top Right. Click it. Android Studio will take care of remaining things.
Also this question similar is to yours. Go through it. It may help.
Add :
build.gradle
defaultConfig {
...
vectorDrawables.useSupportLibrary = true
...
}
And on top of your Activity class:
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
And one last thing put your vector drawables inside any other drawables like selector, LayerList, etc. Something like below:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/drawable_vector" />
</selector>
And use this above drawable everywhere instead of setting vector drawables directly. This will at other places as well whenever you want to use vector drawables on pre-lollipop devices.

Share external dependencies between modules in Android Studio

I'm trying to share 2 external dependencies between 2 modules in Android Studio.
The 2 dependencies are Twitter Core and Twitter4j (a Twitter library extension I'm experimenting with).
Here is the project structure:
Root project 'cineios-test'
+--- Project ':app'
\--- Project ':cineio-broadcast-android-sdk'
I set up the dependencies in my app build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.lgorse.cineios_test"
minSdkVersion 18
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions{
exclude 'META-INF/LICENSE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':cineio-broadcast-android-sdk')
//compile project(':cineio-broadcast-android')
//compile 'io.cine:cineio-broadcast-android-sdk:0.0.9'
compile ('org.twitter4j:twitter4j-stream:4.0.2'){
transitive = true;
}
compile('com.twitter.sdk.android:twitter:1.1.1#aar') {
transitive = true;
}
}
Here is the build.gradle file for the module, which is cineios-android-sdk:
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
// applicationId 'io.cine.android'
minSdkVersion 18
targetSdkVersion 19
versionCode 11
versionName '0.0.11'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile 'com.google.guava:guava:16.0'
compile 'com.loopj.android:android-async-http:1.4.5'
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.android.support:support-v4:20.0.0'
}
Finally here is settings.gradle:
include ':app', ':cineio-broadcast-android-sdk'
project(':cineio-broadcast-android-sdk').projectDir = new File('cineio-broadcast-android/cineio-broadcast-android-sdk')
I know there are answers on SO but they refer adding local libraries as modules - but since these dependencies are remote I'm not sure how to adapt the hints to this situation.
I did try adding the dependencies to the other module (cineios-android) but a) it seems ridiculous to double them up like that and b)that would imply registering a new app in the Twitter API, which will probably lead to errors.
The correct approach really is to specify the dependencies in both the main app and the module.
I did try adding the dependencies to the other module (cineios-android) but a) it seems ridiculous to double them up like that and
There's really nothing ridiculous about it. Don't think of it as trying to "share" the dependency between the main app and the module. Look at it this way: your module depends on Twitter4j and Twitter Core. If you were to reuse that module in a different application, the module should be self-contained and should be able to specify its own dependencies without the parent project needing to set them up. Making all its dependencies explicit does this.
If the parent app also depends on Twitter4j and Twitter Core, and if you use the Maven Coordinate-style remote dependency specs as you have, the build system will ensure that only one copy actually gets linked into the app, so everything will be okay.
b)that would imply registering a new app in the Twitter API, which will probably lead to errors.
I'm not familiar with how that works, so I can't comment on it other than to say that if their API is well designed, hopefully just including the library shouldn't imply something like that. If you're having problems, clarify your question or ask a new one.
In your build.gradle add dependency like below:
dependencies {
compile 'org.openimaj:twitter:1.3.1'
}
You can also use belowed link for more reference :
Gradle Please

Building app with library module cannot find AndroidManifest.xml

I want to build an Android App with AndroidAnnotations.
Here is a simplified version on GitHub which fails to build/pre-process: https://github.com/aiQon/androidannotationsexample
The app is composed of a main app module and a library module.
Both use AndroidAnnotations (AA). The lib module has a workaround to find the AndroidManifest.xml in debug builds (it refers to the release manifest, because gradle does not build the debug variant for libs).
However, the manifest is found for the library module but not for the main app.
The gradle file of the main app is:
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
android {
compileSdkVersion 21
buildToolsVersion "21.0.1"
defaultConfig {
applicationId "de.stelle_beratung.androidannotationslibraryexample"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
apt {
arguments {
androidManifestFile variant.outputs.processResources.manifestFile
resourcePackageName android.defaultConfig.applicationId
}
}
dependencies {
compile project(":mylibrary")
apt "org.androidannotations:androidannotations:3.2+"
compile 'org.androidannotations:androidannotations-api:3.2+'
}
Gradle complains with:
http://pastebin.com/QZtnHcZD
Could someone please point me in the right direction on how to build this simplified project to have a controller Bean in the lib module and reference it successfully in the main app activity by using AA?
I appreciate any help.
Since android gradle plugin 14.4, the following line does not work anymore:
variant.outputs.processResources.manifestFile orvariant.processResources.manifestFile
You have to use this one instead:
variant.outputs[0].processResources.manifestFile
Please note if you have multiple outputs (when using splits), you may want to use another output (other index than zero).
Ok I got it. Was using Android Studio from the Canary Channel. Going back to Beta solved the issue because I could use android gradle plugin 0.12.2. This solved everything.

debug: file not found in Android 1.0

Today I updated to Android Studio v 1.0 and I'm getting the following error when trying to compile whatever project.
....\app\build\intermediates\classes\debug: file not found
The thing is that before updating it I had no problems. Here is the code I'm actually trying to compile.
build.grade
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "razvitrance.testnavdrawerplz"
minSdkVersion 16
targetSdkVersion 20
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:support-v13:21.0.3'
}
build.gradle (for the project)
// 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.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
And the activity code is a simple Navigation Drawer.
Thank you for helping.
This is the erorr i'm getting.
http://gyazo.com/bdf375a160b1662ce4eb0d4e9aed8f30
Check this and this answers.
Generally, you will need to delete your grandle file and let Android Studio generate the one it thinks that it is correct, as it is being mentioned in the given posts. Happened to me too when i upgrated to newer version and that solved my problem.
It seems that Android Studio does not recognize non-alphanumeric symbols in path (cyrillic, for example). I had the same problem, and it was solved with creating project in another folder not containing cyrillic symbols in its path. In your case it may be '#' synmbol that makes a trouble

Android Studio 0.9.0 - Cannot resolve symbols

After 6h spent trying to fix this by myself, AS is driving me crazy. Everything was fine yesterday and today it can't resolve any of the support libs nor the R symbols.
I tried everthing, including all the suggested fixes I found on StackOverflow. No need to tell me to have a look a this post, I already have and none of the solutions work.
Here's what I tried so far :
rebuilding / cleaning the project (many times...),
synchronising the project with Gradle Files,
check that the support lib is up-to-date in the SDK Manager,
invalide Caches / restart AS,
delete the .idea folder and the .iml files of my project, and re-importing it in AS,
update AS from 0.8.11 to 0.9,
eventually I ended up uninstalling AS and reinstalling it from scratch
And none of this fixed my issue...
Something really weird is that I also tried to create a whole new project from scratch and to copy/paste all my classes & resources from my corrupted project to this new one. And it worked for a while (~10 min), until it eventually became corrupted the same way, without any apparent reason.
Moreover, no idea if it's relevant, but when I type "ViewPager" in AndroidStudio and hit CTRL-SPACE, it doesn't suggest me the "android.support.v4.view.ViewPager" class. But if I hit CTRL-SPACE 3 times in a row, it DOES suggest it. So I guess that means that it's able to find the support lib somewhere but not to use it?
Here's my build.gradle :
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
applicationId "com.mathieumaree.library"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:support-v13:21.0.0'
}
Please, help me, otherwise I'm gonna break my computer soon.
Thanks in advance,
Mathieu
EDIT 1 :
I forgot to mention that this occurs only in one of my projects. The others seem to be fine (at least for now).
EDIT 2 :
I also forgot to mention that my project is composed of an application project plus a library module inside it. So here is the app's build.gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
applicationId "com.mathieumaree.materialheaderviewpager"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
compile 'com.android.support:support-v13:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.0'
}
The app Manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mathieumaree.materialheaderviewpager" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.mathieumaree.materialheaderviewpager.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The library manifest :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mathieumaree.library">
<application android:allowBackup="true"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme">
</application>
</manifest>
The main settings.gradle :
include ':app', ':library'
And the main 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:0.14.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
EDIT 3 :
After trying once more to delete all .idea folers & *.iml files and reloading my project, I noticed that AndroidStudio displayed an error at openning :
Accessing invalid virtual file:
file://C:/Users/Mathieu/AppData/Local/Android/android-studio1/sdk/sources/android-21;
original:582; found:-: Accessing invalid virtual file:
file://C:/Users/Mathieu/AppData/Local/Android/android-studio1/sdk/sources/android-21;
original:582; found:-
I'm pretty sure it means it's looking for the SDK to yet another location (AppData/Local...android-21). What I don't understand is :
there's no SDK folder at this location
the SDK path indicated in the Project Structure is not this one
Any idea what all this means?
try addind this to buid.gradle
compile 'com.android.support:support-v4:21.0.0
and change build tools version to 20.0.0
Also create a whole new project and see if the same errors are still present in that project.
Try "Tools" -> "Android" -> "Sync Project with Gradle Files"
Well, still not a clue what caused this problem but it would look like I managed to get rid of it, although I had to create a new project from scratch. What I really don't understand is that I've already done this yesterday and it didn't work out.

Categories

Resources