ClassNotFoundException: after obfuscation - android

I am creating a library. My library has method for open another activity
val ACTION: String
get() = "org.comp.sign.Auth"
internal fun createIntent(input: Pair<AuthorizationParams, Config>): Intent {
return Intent(ACTION).apply {
val loggingData = input.first.parseToPair()
putExtra(PARAMS_TYPE, loggingData.first)
putExtra(PARAMS_FIELD, loggingData.second)
putExtra(CONFIG_DATA, input.second.toData())
}
}
I used to intent-filter cause I would like to do obfuscation in my code, if was opening it without
intent-filter my Activity class would not be obfuscation
library's manifest
<activity
android:name=".config.internal.ui.view.CompActivity"
android:exported="false"
android:screenOrientation="portrait"
android:theme="#style/Theme.Auth">
<intent-filter>
<action android:name="org.comp.sign.Auth" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
when i implementation my lib in another project i throw a exception
java.lang.ClassNotFoundException: org.comp.sign.auth.a.a.d.a.a
Project was finding Activity class, but it has different name
If I used to save class with the proguard rule -keep class !org.comp.sign.auth.config.internal.ui.view.CompActivity
then in my library will be many another files that disappeared when obfuscation
If there is a way around this?
Sorry for my English

Related

android unresolved class .MainActivity errors in manifest file

<meta-data
android:name="..."
android:value=" ...."/>
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
android:name=".MainActivity" here problem. MainActivity unresolved class ?
I want to install my app on google play. But when loading apk it gave com.example error. So I changed the package name. Then I got this error in the manifest file. There are even red errors in the src section of the project.
You might wanna check your java and the xml class of main activity. There must be an error in it.
Or
You could show your class and xml here and describe the problem in detail
PUT MainActivity.java in Same package named com.example.test.MainActivity, it will resolved automatically.
Make sure your MainActivity is in the root package of your project.
Example:
If your package is com.example.demo then path of MainActivity should be com.example.demo.MainActivity
If your MainActivity path is com.example.demo.activity.MainActivity
then your Manifest entry should be like this
<activity android:name=".activity.MainActivity">
EDIT
If you changed your package name then you must use full path of your Activity, like this:
<activity android:name="com.example.demo.activity.MainActivity">

One APK, multiple application modules

I have a project setup with 4 modules that flows like this
Module1 -> Module2 -> Module3
Module4
Module1 and Module4 are both entry points in to the app and need to have their own launch icons
Before I split the app in to modules this worked fine but when I split this into modules Modules 1 and 4 are are treated independent and I can either launch one or the other.
This is fine while developing the app but what I want at the end is to generate one APK that contains all modules and create 2 launcher icons when installed, but this isn't happening because it seems to generate 2 APKs
How do I need to organise this to generate one APK?
I figured it out.
It needs a bit more than just setting the intent filter so I thought I would explain it here in case anyone else is trying this.
Module1 is the application module, Module4 needs to be a library with just the bare definition for an activity.
Then in Module1 manifest you need to create an activity alias to Module4
The process is decribed well here..
http://blog.danlew.net/2014/01/16/preserve-your-launchers-use-activity-alias/
Also because of this Module1 now has a dependency on Module4 too
In your Manifest file write this code at both entry point . it will generate two instance . for ex like this
<activity
android:name=".Activity.Your_module1_entry_activity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and for your second module
<activity
android:name=".Activity.your_module2_entry_activity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

How to add zxing in android studio?

When I add
dependencies {
compile 'com.google.zxing:core:3.0.0'
}
and
dependencies {
compile files('./libs/zxing/core.jar')
}
in build.gradle in both cases it shows error in manifest file
Cannot resolve symbol 'CaptureActivity'
Manifest File is as
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
When i add
com.google.zxing.client.android.captureactivity.jar
in libs folder then Manifest error is solved but it gives
Multiple dex files define Lcom/google/zxing/BarcodeFormat;
Is it necessary to add captureactivity.jar in libs, if not then how to solve manifest error.
The short answer is: CaptureActivity is not part of the core library, and is not meant to be used as if it is a library. It is in android/, and you can reuse parts of that code for your own app, but you should be writing your own app from scratch rather than cloning the Barcode Scanner app, which seems to be your starting point here. Please read https://github.com/zxing/zxing/wiki/License-Questions

Cannot Launch Activity in Android Library Module

To my Android app project, I added a module which contains an activity named "SampleDataMenuActivity". There is nothing special to this activity - it's added using the "New Module" -> "Android Library" dialog in Android Studio and includes the "Hello World" code generated by Android Studio.
The AndroidManifest.xml of the app includes (from the module):
<activity
android:name="com.sample.sampledata.SampleDataMenuActivity" >
<intent-filter>
<action android:name="android.intent.action.SampleDataMenuActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
In the build.gradle of the app:
dependencies {
(...)
compile project(':sampledata')
}
In the settings.gradle of the project:
include ':sampledata', ':app'
In the main activity of my app, I want to navigate to an activity in the module using:
startActivity(new Intent("com.sample.sampledata.SampleDataMenuActivity"));
The project builds just fine, but when I tap the button that should take me to the activity in the module it fails, reporting:
android.content.ActivityNoFoundException: No Activity found to handle Intent ( act=com.sample.sampledata.SampleDataMenuActivity )
What did I miss?
I found the mistake, and perhaps I should remove the question. But as it was upvoted, somone else might be interested in this answer:
The manifest should state:
<activity
android:name="com.sample.sampledata.SampleDataMenuActivity" >
<intent-filter>
<action android:name="com.sample.sampledata.SampleDataMenuActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

JNI not found my other activityy

i have a application on java + c++.
IDE is - visual studio with android plugin.
i have 2 activity : 1-nativeActivity , 2- activity on java.
activity on java is main.
after java activity i start nativeactivity. in java activity there are a purchase manager. i want call to him from a native activity.
<activity android:configChanges="orientation|keyboardHidden" android:name="android.app.NativeActivity"
android:label="#string/app_name" android:theme="#android:style/Theme.Translucent">
<meta-data android:name="android.app.lib_name" android:value="main" />
</activity>
<activity android:name="BillingActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
in onCreate BillingActivity i start nativeActivity.
in native activity i do
jclass billing = env->FindClass("Lcom/crystalreality/crystaltv/BillingActivity;");
but i have
jclass billing = env->FindClass("Lcom/crystalreality/crystaltv/BillingActivity;");
05-20 16:40:55.061: W/System.err(28592): java.lang.NoClassDefFoundError: Lcom/crystalreality/crystaltv/BillingActivity;
The correct usage of FindClass is something like this:
env->FindClass("com/crystalreality/crystaltv/BillingActivity");
I suspect you don't need the "L" at the beginning (and ";" at the end) of your class sig.
jclass billing = env->FindClass("com/crystalreality/crystaltv/BillingActivity");
You should only need L...; form sigs if you're looking for an array class. That's my understanding from these lines of documentation.
Failing that, have you used any obfuscation java-side?

Categories

Resources