Application class in a module's manifest - android

I have added a module within my project and created an Application class which was added to the module's manifest.
public class App extends Application {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
#Override
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics());;
}
}
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mymodule">
<application
android:allowBackup="true"
android:label="#string/app_name"
android:name="com.example.mymodule.App">
</application>
</manifest>
The problem is that I get no suggestions when trying to set the name of my application class within the Manifest. Any ideas why?
EDIT: I already have an Application class in my app module. The reason why I'm doing this is because I want to add a library in that module. How can I achieve this?

You need to type . (dot) and then you will get the suggestion. Like below
android:name=".App"

If you application class is within any package then the name will be
.[package name].[Application class]. If it is outside the any package the just the Application name.If still the problem exist then restart the studio sync,rebuild and clean it and check it once again.Hope this will help you.

Related

Flutter enable multiDex for SDK less than 21

How can I enable multiDex for SDK less than 21.
This page shows how to do it, but it says for API less 21.
If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows:
public class MyApplication extends MultiDexApplication { ... }
So, in Flutter, my application by default overrides io.flutter.app.FlutterApplication and I should make changes in my FlutterApplication class but I couldn't open this file for editing because it is decompiled version. Can anyone help me? It is an issue on Github
Actually I need to create my own java class say MyApplication.java like this.
public class MyApplication extends FlutterApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
After this in AndroidManifest.xml file, change
<application
android:name="io.flutter.app.FlutterApplication" .../>
to
<application
android:name=".MyApplication" .../>

Android Studio Access Denied Error on local app folder

I am in a world of trouble. In a position of inheriting an Android App in Java with a team of C# .Net developers.
I am getting an (Access Denied) error to the projects root app folder C:\Users\user.name\Development\theproject\app
The project builds, cleans and rebuilds no problem but on debug or run, it fails at this step app:transformDexWithInstantRunDependenciesApkForDebug.
In the research so far I am getting lost in setting application permissions in the manifest.xml file but this feels more like a local machine folder permission issue more than an application issue.
I have tried running Android Studio in Adminstrator mode and both it and the emulator appear to be running under my username. I have administration priviliges to my machine.
Any help greatly appreciated. I had never heard of gradle until yesterday.
This is done as you have used multilibrary and the methods exceed the limits.
Modify your build.gradle:
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
include this in application class :
public class YouApplication extends Application {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Add this class name to the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>

Android external Service from a library (AAR, not Shared Service)

I am trying to create an Android Library containing a simple service. For example:
public class BasicService extends Service {
public BasicService() {
Log.d("I", "work");
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
}
I start the service the following way:
startService(new Intent(this, BasicService.class));
The service is compiled into an AAR file and after adding that to an application I get a ClassNotFoundException.
Caused by: java.lang.ClassNotFoundException: Didn't find class "nl.company.example.library.Services.BasicService" on path: DexPathList[[zip file "/data/app/nl.example.aartest-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
I don't need to bind a service as the application does not have to communicate with the service. I also don't need an aidl interface as I don't want to share the service with other apps. I know I need to declare the service at the application side (not library) so I did that the following way:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nl.company.example.exampleApp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="19" />
<application
android:settings... >
<service
android:name="nl.company.example.library.Services.BasicService"
android:enabled="true"
android:exported="true" />
</application>
</manifest>
This is the manifest of my library:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nl.company.example.library" >
<application/>
</manifest>
I've done some research at Stackoverflow/Google and I wasn't able to find an answer to my problem.
Android service in library
Also tried different ways of starting the service (on action etc.) but no good so far.
All help is welcome and my apologies if I made an evil duplicate question.
The BaseService was implementing an interface from another library which was not packaged with the aar file. This caused the application to crash right after starting on a device, because it couldn't resolve the dependency.
public class BaseService implements OtherLibraryInterface {
...
}
Instead of throwing a ClassNotFoundException for the OtherLibraryInterface, Android would throw exactly that exception for the BaseService. Which is very confusing and lead us to believe that there is something wrong with the Service.
Adding the OtherLibrary dependency explicitly as a dependency to the main application solved this issue.

No good example for latest ACRA (Application Crash Report for Android)

I searched a lot about ACRA. Since after the code transferred from code.google.com to Github. All the answer's in SO has bad link's. All the example code's are not so useful as google docs has been deprecated for using it.
So please guide me how the new system woks and how to use it.
First, add ACRA to your project:
Maven
<dependency>
<groupId>ch.acra</groupId>
<artifactId>acra</artifactId>
<version>4.9.2</version>
<type>aar</type>
</dependency>
Gradle
compile 'ch.acra:acra:4.9.2'
Now, you need a java class that extends Application. This is also defined in the manifest so no initialisation of the class is needed!
#ReportsCrashes(
formUri = "http://example.com/reportpath"
)
public class MyApplication extends Application {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
ACRA.init(this);
}
}
In your manifest:
<application android:icon="#drawable/icon" android:label="#string/app_name"
IMPORTANT! ---> android:name="MyApplication" >
You need these permissions: (read logs is not necessary if you do not need to read the logcat)
<uses-permission android:name="android.permission.INTERNET"/>
That is everything you need java-wise. From here it splits in two. If your site supports CouchDB:
Install Acralyzer: https://github.com/ACRA/acralyzer
If your server doesn't have CouchDB, try one of these: https://github.com/ACRA/acra/wiki/Backends

how to create an application havind multidex files with multidex library?

What's the solution for 65k ? I tried almost all the post but still not able to . Working on Android Studio but it is not letting me enable multidex option . Anyone having idea about it?
Any idea how to integrate with eclipse?
For Android Studio and Gradle the answer is here:
https://developer.android.com/tools/building/multidex.html#mdex-gradle
In Eclipse import the MultiDex library project from this location:
[android-sdk]\extras\android\support\multidex\library
Next you have three options:
Option 1
In your AndroidManifest.xml file update your <application> element like so:
<application
name="android.support.multidex.MultiDexApplication">
...
</application>
Option 2
If you use custom Application class make sure you extend MultiDexApplication.
MyApplication.java
public class MyApplication extends MultiDexApplication {
...
}
AndroidManifest.xml
<application
name=".MyApplication">
...
</application>
Option 3
If your application class cannot extend MultiDexApplication for some reason override the following method:
MyApplication.java
public class MyApplication extends Application {
...
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
AndroidManifest.xml
<application
name=".MyApplication">
...
</application>
Source: https://developer.android.com/reference/android/support/multidex/MultiDexApplication.html
Warning: Eclipse build tools do not support multidex. Look here for further info:
Android multidex support library using eclipse
I did this tut and worked http://android-developers.blogspot.com.es/2011/07/custom-class-loading-in-dalvik.html
I have now rhino.jar in a dex file in my asset folder
This problem is solved with Android studio 1.0 and above. We need to set multidexEnabled parameter to true.
That's all we need to implement. So, if anyone what to solve this problem you need to go with android studio.

Categories

Resources