After configuring progaurd, chromecast button doesn't show up and instead text like "PLAY ON.." appears in the Action bar.
I have tried adding below line in config file but no luck
-keep class com.google.sample.castcompanionlibrary.** {*;}
please let me know if i am missing anything.
Thanks.
Related
I am using https://github.com/amalChandran/trail-android this library in my android project. The animation was working perfectly fine. But, after enabling R8, the animation is not working. The library does not have any Proguard suggestion. I added the following block in one of my method,
googleMap.setOnMapLoadedCallback(() -> {
Route normalOverlayPolyline = new Route.Builder(mRouteOverlayView)
.setRouteType(RouteType.PATH)
.setCameraPosition(mMap.getCameraPosition())
.setProjection(mMap.getProjection())
.setLatLngs(mRoute)
.setBottomLayerColor(Color.YELLOW)
.setTopLayerColor(Color.RED)
.create();
map.setOnCameraMoveListener(() -> mRouteOverlayView.onCameraMove(map.getProjection(), map.getCameraPosition()));
Where I have two global variables defined,
public Route route;
public RouteOverlayView mRouteOverlayView;
Now, I have some details in my usage.txt
public void onCameramove(com.google.android.gms.maps.GoogleMap,com.obhai.polyline.trail.RouteOverlayView)
Is there any way to write something in proguard-rules.pro so that R8 doesn't remove this part?
Thanks to #sgjesse for his hint. I finally got my narrowed down proguard rule to keep my feature functioning.
-keep class com.amalbit.trail.AnimationRouteHelper { *;}
adding this rule served my purpose.
I've looked at How to auto import the necessary classes in Android Studio with shortcut? but it doesn't help.
Ctrl+Alt+O does nothing.
When I press alt+enter I get the following:
I do not want this, I wish for it to appear as a normal import at the top of the file.
What are these shortcuts called in Android Studio? This program makes it complicated to edit such simple shortcuts.
I also have auto-imports, but it isn't working:
Finally after hours of trail and error the following settings is what fixed it:
Pressing Ctrl + Space on Mac will open a dialog to choose which library to import.
check this link for detail ans
https://stackoverflow.com/a/37362700/3288890
or
goto file -> setting select keymap and search for auto import and add keyboard short cut
I am trying to add the cast icon to the ActionBar using the CastCompanionLibrary's helper method:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.main, menu);
mDataCastManager.addMediaRouterButton(menu, R.id.media_route_menu_item); // This one
return true;
}
I have this as my menu.xml as specified by the PDF that is included with the companion library:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/media_route_menu_item"
android:title="#string/media_route_menu_title"
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
app:showAsAction="always"/>
</menu>
However, nothing shows up in the ActionBar. No errors are thrown, nothing at all is visible. If I add a different menu item just to see if everything with my menu is set up correctly, that item shows up fine - it is just this cast action menu item that isn't showing up.
I have tried changing the "app" prefixes to "android", but then I get a NullPointerException somewhere deep in the library, and I have tried giving the menu item a different, visible icon. Nothing helps.
In AndroidStudio, the menu preview shows a menu item with the title "Play on...", so it seems like this should work.
What am I doing wrong?
You have to register your chrome-cast as a testing devise for you to be able to detect the chromecast devise from the Android.
Check the full SDK guide
Check the developer console registration. You have to register you chromecast devise in the console here, or else it is not detectable
Update: If nothing works, you may try to publish your app in the chromecast dev console as a last resort.
As mentioned by one of the chromecast developer try to access http://<chromecast-ip>:9222 from browser and see if you are able to see any thing.
Sometimes, these types of errors happen because proguard changes the name of the object and/or functions.
One possible solution is to add these to your progaurd configuration files:
-dontwarn android.support.v7.**
-keep class android.support.v7.internal.** { *; }
-keep interface android.support.v7.internal.** { *; }
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
I actually had this exact error on the exact line and I didn't have my proguard configured properly for the support library.
In my case after device registration I forgot reboot chromecast device
CastCompanionLibrary and MediaRouteActionProvider are written for AppCompat ActionBar and not Sherlock ActionBar. It is strongly recommended to move your project to AppCompat since Sherlock ActionBar is deprecated so moving to AppCompat is generally a good move for your project; making that move is not difficult (see, e.g. this article)
I am trying to add the Pinit button to my Android App. I have downloaded the SDK and copied the pinit-sdk-1.0.Jar into my Project/libs folder. I'm even able to make the necessary PinItButton import to my code. But for whatever reason, my XML isn't finding the Button widget, and so I tried to add it just using Java with this code:
LinearLayout ll = (LinearLayout)findViewById(R.id.pinterest_layout);
PinItButton pinit = new PinItButton(this);
ll.addView(pinit);
I know this is the correct way to add something using code because I tested it by adding a generic Button first. I run my project then, and it crashes on the line where I set up the PinItButton. This is the error that my logcat spat back at me:
07-22 01:19:52.160: E/AndroidRuntime(32367): java.lang.NoClassDefFoundError: com.pinterest.pinit.PinItButton
I believe that I'm understand what it is telling me, but what else should I be attempting then to create the PinIt button? Any help would be great. Thank you!
It was #Kai who helped me figure out my problem. I needed to check my libraries. I did that by going to project --> Properties --> Java Build Path --> Order and Export tab, then checking the library and clicking OK. My problem was then solved!
I have some html files in res/raw which I open in WebView. But after obfuscation they are unable to load.
I ran into exactly this same issue. I have my help html file in raw and after obfuscation I run my app and get an error that the file could not be found.
Here is my HelpActivity class:
public class HelpActivity extends BaseActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// requesting to turn the title OFF
//requestWindowFeature(Window.FEATURE_NO_TITLE);
// making it full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.help);
setTitle(getString(R.string.help_title));
WebView webView = (WebView) findViewById(R.id.webView);
webView.loadUrl("file:///android_" + getString(R.raw.how_to_play_zeewee));
}
}
I fixed this issue by adding the following to my proguard.cfg file:
-keepclassmembers class **.R$* {public static <fields>;}
-keep class **.R$*
You probably already have the first line, but this does not prevent the issue. Adding the second line eliminated the issue completly. I don't think the first line is still needed, but I have not tested that yet -- and since it currently works... ;).
Suggested in an answer in this question -
-keep class **.R$*
isn't the most elegant solution since it instructs ProGuard to preserve all of the R classes regardless of the package they are in.
Having the same problem with WebView, the error I see in my Logcat:
... E/AndroidProtocolHandler: Unable to open resource URL:file:///android_res/raw/$MISSING_RESOURCE_NAME.css
java.lang.ClassNotFoundException: Didn't find class
"my.app.package.R$raw" on path: DexPathList[[...
The instruction with maximum restrictions I added to my proguard-rules.pro file:
-keepnames class my.app.package.R$raw { public static <fields>; }
Obviously Since R class contains only fields and all of these fields have public static type, in practice, there should no be the difference between the one above and
-keepnames class my.app.package.R$raw { *; }
However, here I'm
NOT disabling shrinking and obfuscation for all of the rest inner classes in R other than raw.
targeting R in one specific package only.
That approach should be better in case if you have more than one module in your project that provides its own resources that may not be needed for the one particular APK you are building (having, let's say, more than one android_application modules – APK sources – in your project as well).
To understand the difference between -keepnames and -keep, please, refer to the following.
Distinguishing between the different ProGuard -keep directives - Tue May 29 04:10:50 MSK 2018
Create a file in raw folder
keep.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="#raw/*">
</resources>
That's it! It will keep all the files in raw folder, If you want to restrict it to only one particular file you can use
tools:keep="#raw/fileName"
Note that you should not add file extension in the end so it shouldn't be filename.html