Android cannot read packageName from AndroidManifest.xml - android

have a problem with android studio. Not sure what is wrong or missing from the files, here is my build.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.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "aaa.myplugin"
minSdkVersion 15
targetSdkVersion 24
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/classes.jar')
}
//task to delete the old jar
task cleanJar(type: Delete) {
delete 'release/MyPlugin.jar'
}
//task to export contents as jar
task exportJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('release/')
include('classes.jar')
rename('classes.jar', 'MyPlugin.jar')
}
exportJar.dependsOn(cleanJar, build)
And here is my manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="aaa.myplugin">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
</application>
</manifest>
There are several questions with the same error, but none of the solutions did work for me. Please help if you had a similar problem.

you have used wrong plugin
apply plugin: 'com.android.library'
above plugin is for library projects
applicationId is for app, it cannot be used with libraries
so add application id to the build.gradle file which has following plugin
apply plugin: 'com.android.application'

You can open Android studio,make sure that you project is open with the project model,just like the screen-capture .Now ,you can try to delete the package that has been referred to the error.

Related

Android Studio generated apk installs but doesn't open

I have installed my apk bundle that I created via Build APK(s) and it installs but won't let me open it, and it doesn't show in the menu.
I've already checked Project/App/src/main/AndroidManifest.xml and Project/build.gradle and settings.gradle as well but I don't find anything odd.
android:protectionLevel="signature" is not in any of the previous files.
minifyEnabled is FALSE
I've read somewhere to edit my manifest and add or something (I can't find the post right now). I did it, and the app began to have gradle errors, and showed me another manifest that had those lines written.
Here's my Project/App/src/main/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.multicobertura">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.Multicobertura" />
</manifest>
build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
settings.gradle
include ':app'
rootProject.name = "multicobertura"
I am clueless
EDIT: I tried adding "entry points"
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.multicobertura">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.Multicobertura" />
<activity
android:name=".NewEntryPoint"
android:label="#string/title_activity_second" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</manifest>
But
build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app build.gradle
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.multicobertura"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
EDIT2: I've already created a new android studio project, copied the files and yarn insalled the modules, built the app and failed as well. Anyone?

Execution failed for task ':app:transformClassesWithJarMergingForRelease [duplicate]

I am trying to build a signed Apk of my project and i get the following error:
Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/common/internal/zzv$zza$zza.class
When I choose the debug build type I got no errors and everything works fine. I searched for a while to fix this but i found nothing useful.
My build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.danielsous.demos"
minSdkVersion 14
targetSdkVersion 24
multiDexEnabled true
}
buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
dependencies {
compile files('libs/scanditsdk-android-4.7.5.jar')
compile 'com.android.support:support-v4:24.2.1'
compile 'com.github.attenzione:android-ColorPickerPreference:e3aa301016'
compile 'com.google.firebase:firebase-messaging:9.4.0'
compile 'com.google.code.gson:gson:2.7'
}
The other 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:2.1.3'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
}
}
I had 1 library and a second library made from an aar file which contained multiple resource with the same names ( pngs files with same names, strings with the same ids, layouts with the same files ). Removing the aar library fixed my issues
It seems that you have more than one libraries added for printHelper.
Every time that you face a duplicate entry error run ./gradlew app:dependencies and make sure that there is no duplicated versions of a same module.

How to use Realm in a library

i'm trying to understand how to use Realm in a library that i'm making, i now understand RealmModules after a couple of days of research (if someone from Realm reads this, you should really improve on documentation about use in libraries). I've made a simple class that gives me the realm with library configuration:
object ChatRealm {
fun getChatRealm(): Realm{
val config = RealmConfiguration.Builder()
.name("mtchat_realmDB")
.schemaVersion(2)
.deleteRealmIfMigrationNeeded()
.modules(ChatModule())
.build()
return Realm.getInstance(config)
}
}
the module is this
#RealmModule(library = true, allClasses = true)
class ChatModule {}
and in the project Application class i setup realm like this
class App: Application() {
override fun onCreate() {
super.onCreate()
initRealm()
setupRealm()
}
private fun initRealm() {
Realm.init(this)
}
private fun setupRealm(){
Realm.setDefaultConfiguration(
RealmConfiguration.Builder()
.deleteRealmIfMigrationNeeded()
.modules(Realm.getDefaultModule(), ChatModule())
.build()
)
}
}
Now the trouble i'm having is that the build is failing or the app is crashing for various reasons based on how i configure the gradle files.
My :app gradle is this
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'realm-android'
repositories {
maven { url "https://jitpack.io" }
maven { url 'https://maven.google.com' }
mavenCentral()
}
buildscript {
repositories {
jcenter()
}
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary= true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:26.0.2'
compile 'com.android.support:design:26.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:support-vector-drawable:26.0.2'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile project(':mtchat')
}
and my library gradle is this
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
repositories {
maven { url "https://jitpack.io" }
maven { url 'https://maven.google.com' }
mavenCentral()
}
buildscript {
repositories {
jcenter()
}
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile "com.android.support:appcompat-v7:$compat_version"
compile "com.android.support:support-v4:$compat_version"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "com.android.support:cardview-v7:$compat_version"
compile "com.android.support:recyclerview-v7:$compat_version"
compile "com.android.support:design:$compat_version"
compile "de.hdodenhof:circleimageview:2.1.0"
compile 'com.github.bumptech.glide:glide:4.1.1'
compile 'com.android.volley:volley:1.0.0'
}
and this is my project gradle
buildscript {
ext.kotlin_version = '1.1.4-3'
ext.compat_version = '26.0.2'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.realm:realm-gradle-plugin:3.7.2"
// 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
}
and based on if i add or not the apply plugin: 'realm-android' to the :app module i get either RealmObject "X" is not part of the schema for this realm or if i add the plugin to the app gradle it fails to build the project completely.
Is there anyone that has used Realm in a library and wants to explain how, clearly and in depth, maybe this could be used as future reference
EDIT: With the above configuration i get this error when building
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lio/realm/ChatRealmProxyInterface;
EDIT 2:
I managed to get it working by defining modules for both app and library and avoiding naming the realm models in the app the same as the ones in the library ( is this required? Or is there a way to isolate the library models so that the user can use the same names that the library models use?) Still this took me 2 days of research and i'm still unsure if I'm doing it right. It would be REALLY great if someone with more knowledge than me made a nice tutorial or something.
you are facing Over 64K Methods Multiple dex file problem not related to realm library you need to add dependencies
Configure your app for multidex
android {
defaultConfig {
...
multiDexEnabled true
}
productFlavors {
dev {
// Enable pre-dexing to produce an APK that can be tested on
// Android 5.0+ without the time-consuming DEX build processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the production version.
minSdkVersion 14
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
If you do not override the Application class, edit your manifest file to set android:name in the tag as follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows:
public class MyApplication extends SomeOtherApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Add this to your project gradle file
dependencies {
classpath "io.realm:realm-gradle-plugin:3.5.0"
}

How to fix VectorDrawableCompat configuration error in Android Studio?

I created a project in Android studio. Even without modifying any single character in the project I cannot run it. It gives following error.
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.kk.myapplication/com.kk.myapplication.MainActivity}:
java.lang.IllegalStateException: This app has been built with an
incorrect configuration. Please configure your build for
VectorDrawableCompat.
These are the codes.
MainActivity.java :
package com.kk.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Manifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kk.myapplication">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
build.gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.kk.myapplication"
minSdkVersion 19
targetSdkVersion 24
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:24.2.0'
}
build.gradle(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.5.0'
// 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
}
How can I fix this issue? I did not change anything in the project Any Help be Appreciated.
Here you will get this issue.
https://code.google.com/p/android/issues/detail?id=214182
Solution was to upgrade the gradle plugin to v2.0+ (upgraded to 2.1.0)
add this in your dependency.
{
classpath 'com.android.tools.build:gradle:2.1.0'
}
and sync the project.
Edit :
change this
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
to this
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
This is old, but another option might be for your activity to inherit from Activity instead of AppCompatActivity. There's probably a variety of other considerations that might come into play, but that worked for me.
Seems this is an issue with incompatible gradle version reported here.. Google issue
Updatating gradle version may fix this -
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
Add into your build.gradle files
defaultConfig {
applicationId "com.example.myApp"
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
generatedDensities = []
}
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}

How to import android github example with repositories and dependencies definitions

I know there are similar questions like this but i'm new in android development and i need to learn how to import an example defining repositories and dependencies in the build.gradle project file.
After several tries i can't figure out which is the right way...
The example is this one https://github.com/neokree/MaterialNavigationDrawer
When i load the project in android studio i get an error "Configuration with name 'default' not found.", and it's ok.. i know that i have to modify the build.grandle file
repositories {
mavenCentral()
}
dependencies {
compile 'it.neokree:MaterialNavigationDrawer:1.3.3'
}
But where i have to add/replace these rows? In the buildscript area? in the allprojects? i get "Gradle DSL method not found: 'compile()'" error or fix plugin version alert if i try to change something.
original build.grandle
// 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.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
}
Your problem is in setting.gradle file in the MaterialNavigationDrawer project. As you can see
include ':app', ':MaterialNavigationDrawerModule'
it requires MaterialNavigationDrawerModule project to build. Go to New > Import Module and import MaterialNavigationDrawerModule.
Update build.gradle in MaterialNavigationDrawer\app to
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "it.neokree.materialnavigationdrawer"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName '1.0'
}
buildTypes {
release {
//runProguard false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
compile project(':MaterialNavigationDrawerModule')
}
Update build.gradle in MaterialNavigationDrawer\MaterialNavigationDrawerModule to
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName 'dev'
}
buildTypes {
release {
}
}
productFlavors {
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.balysv:material-ripple:1.0.1'
}
In MainActivity i deleted missing import
and rewrite Intent
to
Now it's working.

Categories

Resources