Branch.io does not work with multidex because of manifest conflict - android

Branch wants me to use the "android:name" in the manifests file, but I already use it for multidex. So, how to overcome this conflict?
<application
...
//android:name="io.branch.referral.BranchApp"
android:name="android.support.multidex.MultiDexApplication"
...
</application>

This is the entire code of BranchApp:
public class BranchApp extends Application {
#Override
public void onCreate() {
super.onCreate();
if (BranchUtil.isTestModeEnabled(this) == false) {
Branch.getInstance(this);
} else {
Branch.getTestInstance(this);
}
}
}
Make a custom Application class that extends MultiDexApplication, and use this override for the onCreate and you're good.

The Branch SDK has its own custom activity and application class. Other plugins that use their own custom activity and application classes can cause "conflicts" between these classes. To resolve these conflicts:
Create an empty android library
Add the Branch plugin along with the other plugins into your project
Create a custom Activity and Application class that will contain the custom logic for all your plugins
Build your library
Add your library into Unity project
Change android:name to name of your custom Application class in the application tag of your Manifest
Change android:name to name of your custom Activity class in the activity tag of your Manifest
Some Plugins expand the default AppController the same was as Branch does like Cardboard SDK plugin. To resolve conflicts:
Merge all custom AppControllers in one.
Comment code in other AppControllers (or delete other AppControllers).
Here are some Code Samples for resolving conflicts with other 3rd party plugins
If you still face any issues, please write to integrations#branch.io with the details.

Related

Getting Missing Manifest class or ClassNotFoundException after Android Studio update

I have defines custom permissions in its manifest and the Android Gradle plugin typically generates a Manifest.java class that includes your custom permissions as String constants. The plugin packages this class with your app, so you can more easily reference those permissions at runtime. but after the android studio update it's not working.
As per google announcement Generating the manifest class is currently broken in Android Gradle plugin 3.6.0 and higher. If you build your app with this version of the plugin, and it references the manifest class, you might see a ClassNotFoundException exception. To resolve this issue, do one of the following:
Reference your custom permissions by their fully-qualified name. For example,
"com.example.myapp.permission.DEADLY_ACTIVITY"
Define your own constants, as shown below:
public final class CustomPermissions {
public static final class permission {
public static final String DEADLY_ACTIVITY="com.example.myapp.permission.DEADLY_ACTIVITY";
}

Timber Not Logging in Kotlin Android

Timber is a great library for logging in Android. In Kotlin classes though, doesn't output anything. How can I fix this?
MainActivity.kt code:
Timber.e("Timber Log 1")
Log.e("MainActivity", "Log 1")
Gradle:
I've tried the regular Java Timber:
implementation 'com.jakewharton.timber:timber:4.7.1'
And this Kotlin specific wrapper:
implementation 'com.github.ajalt:timberkt:1.5.1'
Same result. No output with either. Only from the Log.e()
The first step of Timber is to plant the tree as mentioned in docs
Behavior is added through Tree instances. You can install an instance
by calling Timber.plant. Installation of Trees should be done as early
as possible. The onCreate of your application is the most logical
choice.
And use the debugTree
The DebugTree implementation will automatically figure out from which
class it's being called and use that class name as its tag. Since the
tags vary
If you don't do this then you will have no logs entry and do this as soon as possible, like in oncreate or better inside application class so do this
Timber.plant(Timber.DebugTree());
I have faced same problem, using Kotlin and Android studio 3.6
Follow these steps:
Add the following in build.gradle(Module: App)
implementation 'com.jakewharton.timber:timber:4.7.1'
Initialize Timber in Application Class:
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
if(BuildConfig.DEBUG){
Timber.plant(Timber.DebugTree())
}
}
}
Add the Application class(MyApp) to the Manifest (AndroidManifest.xml)
<application
android:name=".MyApp"
Now you can use Timber: Timber.i("Timber logs")
Also can use custom tags if you wish: Timber.tag("Yo").I("used custom tag for logs")
In my case it was wrong BuildConfig import
import org.koin.android.BuildConfig
but my app has
import com.company.example.BuildConfig
Probably late to the party but my problem was the my phone was set to "Charge only" and not "file transfer". Apparently I was allowed to build and run, but logs were blocked
EDIT Another solution:
Check your RUN tab in the bottom of Android Studio. Sometimes the logs get output to there instead
For me it started showing up when I commented the Debug check
// if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree());
// }
I don't know why this is working because the build varient is selected to debug only.

How to use Android Service from other project?

I want to use an external project that is implemented as Android service. The service is used by adding it to the manifest:
<service android:name="com.my.ext.service"/>
But when I addthis line, I get the error:
Unresolved class 'TimerService' less... (⌘F1)
Validates resource references inside Android XML files.
And when I add the layout in my project:
<com.my.ext.service
android:id="#+id/myview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
I get the error that
the class could not be found
I have imported the external service as an extra project into my Android Studio. How can I use the other project as a service for this project?
You can not use Your service class as XML layout.
You can use that service using
<service android:name="com.my.ext.service"/>
and execute that service from Main activity of your app using:
private Intent OtherService;
OtherService = new Intent((Context)this, (Class)YOURSERVICE.class);
MainActivity.this.startService(MainActivity.this.OtherService);

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.

Android Annotations framework doesn't seem to generate anything

I'm trying to use Android annotations framework because it seems quite powerful. I'm quite stuck to configuring my first project based on it.
I followed every step of the wiki but it doesn't generate any file after a build.
So when I ask for a generated class from the manifest:
<activity android:name=".MyActivity_"
android:label="#string/app_name">
I get an exception:
java.lang.ClassNotFoundException
My activity is exactly the same one as in the wiki:
#EActivity(R.layout.main)
public class MyActivity extends Activity {
#ViewById
EditText myInput;
#ViewById(R.id.myTextView)
TextView textView;
#Click
void myButton() {
String name = myInput.getText().toString();
textView.setText("Hello "+name);
}
}
Any ideas?
EDIT: Just found out a directory ".apt_generated" is made but it's empty after the build.
This seems to be an AndroidAnnotations bug, and should be reported on the dedicated bug tracker, here : http://code.google.com/p/androidannotations/issues/entry . You could also use the AndroidAnnotations mailing list, http://groups.google.com/group/androidannotations
First, I have a few questions :
Which IDE do you use : Eclipse, Netbeans, IntelliJ ? Which version ?
Do you use Maven, Ant, or only your IDE to build the project ?
Your problem may be due to a few things : annotation processing not triggered, a bug in AA, or the files generated in a folder not part of the classpath.
In Eclipse, you may get more information from the "Window > Show View > Error Log" view. If annotation processing is triggered, you should see some messages about AndroidAnnotations.
For other people who are running into this and the leading answer doesn't work, run a build and then search for the file androidannotations.log somewhere in the project. This log file is generated and may hint at what is wrong.
For me, it had a warning message that it could not locate AndroidManifest.xml. Though this seemed like just a warning, it was actually the cause of the error... Not finding my AndroidManifest.xml file resulted in it not generating some of the classes it should have.
Check if you have the xml file. If not, the solution is obvious. If you do have it, the typical reason AA cannot find the file is because it is in a non-standard location -- AA recursively checks the parent directories above where it generates files for this xml file and will fail if it's not there. In my case, my AndroidManifest.xml was located in [project root]/app/src/main which is not a direct ancestor folder so that was the problem.
You can specify where your xml file is in your project build.gradle:
android {
defaultConfig {
javaCompileOptions {
annotationProcessorOptions {
arguments = ["androidManifestFile": "specify_location_of_AndroidManifest.xml_here"]
}
}
}
}

Categories

Resources